Getting number of iteration

George Sakkis gsakkis at rutgers.edu
Fri May 6 12:06:48 EDT 2005


"Florian Lindner" wrote:

> Hello,
> when I'm iterating through a list with:
>
> for x in list:
>
> how can I get the number of the current iteration?
>
> Thx,
>
> Florianfor

in python 2.3+:

for i,x in enumerate(sequence):
    print "sequence[%d] = %s" %(i,x)


George




More information about the Python-list mailing list