Like everyone else:
for i, val in enumerate(data):
print i, val
but also
for i, val in enumerate(data, 1):
print i, val
In other words, you can specify as starting value for the index/count generated by enumerate() which comes in handy if you don't want your index to start with the default value of zero.
I was printing out lines in a file the other day and specified the starting value as 1 for enumerate()
, which made more sense than 0 when displaying information about a specific line to the user.