if you look up how array.map works, you'll see that the first argument is the current element in the array as it iterates through.
One question. Maybe this is obvious but why does n automatically equal the item being modified by the map in the map method the the array x?
Well, i tried not to use recursion (which means a worse time complexity) but failed because of "bananas". And finally i get the same solution with such a huge brunch of people.
But I still wonder a better algorithm. Can anyone find one?
I feel regex is more difficult to understand so this type of solutions look more intuitive and friendlier.
Whats wrong with regex?
Iterating one time is orthogonal to using exceptions for control flow, so it doesn't really answer the question. I think using exceptions for control flow is considered less evil in Python than in other languages, although it's still questionable. But best practices votes here are so random that no one knows if it's best practices at all )
yes, this way you traverse the list only one single time
This comment is hidden because it contains spoiler information about the solution
Brilliant solution! One line code, simple and without using regex.
we need new vote solution like: readability
Thanks, that was fun!
Still studying at Gla Uni?
Are you still studying at G.Uni ?
Or more generally, for any object that has length property.