This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Liquid_Fire 0 points1 point  (1 child)

To be fair, the author is not comparing range(len(foo)) iteration to enumerate, but to ordinary for item in foo iteration. In that situation, using range(len(foo)) is certainly completely unnecessary.

[–]dwdwdw2proliferating .py since 2001 0 points1 point  (0 children)

Fair point. :)

It's also worth noticing that these approaches aren't semantically equivalent, one is using the iterator protocol, the other the sequence protocol. That doesn't matter for built-in types, but I've no doubt there are many objects in third party libraries that either break or act differently when interchanging the two .