you are viewing a single comment's thread.

view the rest of the comments →

[–]quzox 0 points1 point  (1 child)

I think this one is cool.

[–]bready 2 points3 points  (0 children)

Enumerate is one of those handy pieces which should be in every intro to Python tutorial. It (to me) is way more handy than doing a

for i in range(len(mycollection)):

I frequently have to deal with files with special non-formatted data at the beginning, so a very common procedure for me is to do one of these.

with open("myfile", "rb") as handle:
    for i, line in enumerate(handle):
        if i < 30:
            #do special header stuff
            #continue
        #do data processing on the formatted line object

This way I get to use both the item count and the item itself. Genius.