Thanks for the extensive feedback!
Agree with 2, a lot of people use them too frequently and we should be careful here.
I also agree that range(len()) is fine and might be better suited for a beginner. I would never teach a beginner this method the first time I'm showing the for-loop. But as I said in the beginning, I wanted to show how the code can be more elegant and Pythonic. I'm not sure if better readability always has to mean that the code should be suited for a complete beginner. And the enumerate function shouldn't be too hard to understand once someone learned about it.
I also prefer enumerate anytime. range(len()) seems to defeat the motto of “simple over complex”. enumerate seems quite descriptive to me (non-English speaker) and otherwise once explained falls flat. If you are concern about variable unpacking...it makes sense to iterate over an index if you come from C, but python “for-each” approach seems to me more readable. IMHO ❤️
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thanks for the extensive feedback!
Agree with 2, a lot of people use them too frequently and we should be careful here.
I also agree that range(len()) is fine and might be better suited for a beginner. I would never teach a beginner this method the first time I'm showing the for-loop. But as I said in the beginning, I wanted to show how the code can be more elegant and Pythonic. I'm not sure if better readability always has to mean that the code should be suited for a complete beginner. And the enumerate function shouldn't be too hard to understand once someone learned about it.
I disagree that it is more elegant, my personal opinion is good code can be read by a non coder, at least from an overview perspective.
With the other solution they would struggle as it requires inside knowledge, whereas range and len are much more obvious.
I also prefer
enumerate
anytime.range(len())
seems to defeat the motto of “simple over complex”.enumerate
seems quite descriptive to me (non-English speaker) and otherwise once explained falls flat. If you are concern about variable unpacking...it makes sense to iterate over an index if you come from C, but python “for-each” approach seems to me more readable. IMHO ❤️