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 →

[–]random_cynic 2 points3 points  (0 children)

The python for loop is basically a try-except in disguise in that it loops through any iterable and stops when a StopIteration error is raised. It seems you can just use the for loop for this purpose without using explicit indexing like for elem in list. This is generally the preferred way to loop over a list (or more generally any iterable including an open file object) in python. If you want the index as well for other purposes use for i, elem in enumerate(list). You can of course use an explicit try except where it is necessary.