enumerate function in python; pyTip

When looping through a sequence, the position index and corresponding value can be retrieved at the same time using the enumerate() function.



>>> for i, v in enumerate(['tic', 'tac', 'toe']):
... print i, v
...
0 tic
1 tac
2 toe

No comments: