DEV Community

Discussion on: 11 Tips And Tricks To Write Better Python Code

andrewharpin profile image
Andrew Harpin

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.

Thread Thread
aezore profile image
Jose Rodriguez

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 makes sense to iterate over an index if you come from C, but python “for-each” approach seems to me more readable. IMHO ❤️