python enumerate
>>> a = [1, 2, 3] >>> for index, item in enumerate(a): print index, item 0 1 1 2 2 3
>>> b = (1, 2, 3) >>> for index, item in enumerate(b): print index, item 0 1 1 2 2 3
>>> c = {'a':1, 'b':2, 'c':3} >>> for index, item in enumerate(c): print index, item 0 a 1 c 2 b
>>> d = "hello world" >>> for index, item in enumerate(d): print index, item 0 h 1 e 2 l 3 l 4 o 5 6 w 7 o 8 r 9 l 10 d