Get number of iteration

Skip Montanaro skip at pobox.com
Thu Jan 29 11:26:53 EST 2004


    Florian> If I iterate through a list, is there a way I can get the
    Florian> number of the iteration: first, second, third, ...

Sure:

    >>> for i, what in enumerate(["three", "four", "five", "six"]):
    ...   print i, what
    ... 
    0 three
    1 four
    2 five
    3 six

Skip




More information about the Python-list mailing list