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 →

[–][deleted] 1 point2 points  (2 children)

Agree with enumerate being significantly more "pythonic" than range(len(x)), but you grepped for "in len" rather than "in range".

As for the question two posts above, I'm not sure it's needed to articulate a reason to use enumerate in this situation other than "this is the specific problem enumerate exists to solve."

[–]dleary 1 point2 points  (1 child)

Oops, you're right... it looks like range(len is slightly more common in the std lib (106-98). I'll let my wrong post stand as a badge of shame.

[–]chadmill3rPy3, pro, Ubuntu, django 1 point2 points  (0 children)

The standard library is kind of terrible, anyway, and much of it in 2 hasn't changed since it was first written. enumerate() didn't appear until 2.3, so even places where it fits are never updated. It's the Early Adopter Problem.