![]() |
|
[Python] Reverse array challenge code I wrote - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Python] Reverse array challenge code I wrote (/showthread.php?tid=6122992) |
Reverse array challenge code I wrote - Doc - Nov 23, 2020 Posting this here looking for constructive criticism. If anyone's got any tips/advice on things I could've done better/differently, please feel free to say so. The code challenge was:
Code # reverse an array challengeI dunno if I got the bonus, although I DID get a lotta much needed experience using numpy for certain things, so at least there's that. Anyway lemme know what you guys think. RE: Reverse array challenge code I wrote - Qismon - Dec 1, 2020 Code def reverse_array(normalArray):RE: Reverse array challenge code I wrote - vorticalbox - Dec 1, 2020 (Dec 1, 2020 09:07 AM)Qismon Wrote: I would say using pythons list fucntiosm would fall under pythons built in reverse. RE: Reverse array challenge code I wrote - SecuroServ - Dec 1, 2020 I think what they are looking for is, loop over the array, switch first item with last item, second item with second last item etc until you reach the middle. I know using a library isn't in their constraints, but I'm pretty sure they also mean that your thing isn't allowed because they are looking for complexity like they said RE: Reverse array challenge code I wrote - vorticalbox - Dec 1, 2020 (Dec 1, 2020 09:27 AM)SecuroServ Wrote: I think what they are looking for is, loop over the array, switch first item with last item, second item with second last item etc until you reach the middle. Completely agree. No packages allowed. He is my solution PHP Code RE: Reverse array challenge code I wrote - L E G I Ø N - Dec 2, 2020 This is the easiest solution I could think of. Just looping through the original array backwards and adding all the items to a new array. PHP Code RE: Reverse array challenge code I wrote - vorticalbox - Dec 2, 2020 (Dec 2, 2020 07:14 AM)L E G I Ø N Wrote: This is the easiest solution I could think of. Just looping through the original array backwards and adding all the items to a new array. Should it not be this? PHP Code RE: Reverse array challenge code I wrote - Doc - Dec 8, 2020 Honestly it was kinda confusing for me to figure out how to go about doing this, primarily because Python doesn't technically have arrays, it has this weird kind of "lists" (I actually saw a pretty good meme about that recently) that can be a bit confusing to work with. Trying to reverse an array "in-place" (which was what I was originally wanting to do) is something I'd think is easier and more straightforward when using languages that have "normal" arrays. RE: Reverse array challenge code I wrote - synchronizing - Dec 9, 2020 This will reverse even and odd lists with almost zero memory space used, and quicker than most other solutions since it only iterates to half of the length of the list (though same big O). PHP Code |