If you use the enumerate function in python, it will return the index together when you run the extended for loop.
>>> for i, s in enumerate(['a', 'b', 'c']):
... print i, s
...
0 a
1 b
2 c
>>>
>>> for i, s in enumerate([('a', 'b'), ('c', 'd'), ('e', 'f')]):
... print i, s
...
0 ('a', 'b')
1 ('c', 'd')
2 ('e', 'f')
I don't plan to use it for now, but it looked interesting.
Recommended Posts