Miner Phil

The place where I unearth useful bits


Python Enumerate

I find myself programming in a variety of languages these days. Today, I found a nugget of information pertaining to retrieving the index of a for-each-loop’s iteration.

 Python |  copy code |? 
1
data = ( 'a', 'b', 'c' )
2
for i, f in enumerate( data ):
3
    print "%d => %s" % ( i, f )

From:
http://zerokspot.com/weblog/2007/03/12/for-loop-with-index-in-python/

Tags:

Leave a Reply

You must be logged in to post a comment.