Next / Previous / Contents / TCC Help System / NM Tech homepage

13.10. enumerate(): Step through indices and values of a sequence

Given a sequence S, this function produces an iterator that iterates over the pairs of values (i, v) where each i is a position in S, and each v is the corresponding value. For more information on iterators, see Section 17.2, “Iterators: Values that can produce a sequence of values”.

>>> L = ['Ministry', 'of', 'Silly', 'Walks']
>>> for where, what in enumerate(L):
...     print "[%d] %s" % (where, what)
... 
[0] Ministry
[1] of
[2] Silly
[3] Walks