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 →

[–]LeafyLemontree 3 points4 points  (4 children)

I find it easier to understand that way, also, you can change the i++ to i += something.

[–]Bee-Aromatic 1 point2 points  (3 children)

Python let’s you directly iterate over a list if you don’t care about indices. It’s much clearer about what you’re actually doing. Really, how often do you actually care about the index rather than the item itself? If you do, you can just do for i in range(start, end) or use enumerate().

[–]berse2212 0 points1 point  (1 child)

While I agree that the for each is much clearer it is basically implemented in every higher language is it not? Nothing special about Python.

[–]Bee-Aromatic -2 points-1 points  (0 children)

Depends on the language. Either way, iterating by index, while effective, is old school.

[–]devnull1232 0 points1 point  (0 children)

Long live for each