Bill Mill <[EMAIL PROTECTED]> writes:
> On 5/6/05, Florian Lindner <[EMAIL PROTECTED]> wrote:
>> Hello,
>> when I'm iterating through a list with:
>>
>> for x in list:
>>
>> how can I get the number of the current iteration?
> Earlier:
>
> n = 0
> for x in lst:
> print "iteration %d on element %s" % (n, x)
> n += 1
Just for the record, the old idiom was:
for n in xrange(len(lst)):
x = lst[n]
print "iteration %d on element %s" % (n, x)
<mike
--
Mike Meyer <[EMAIL PROTECTED]> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
--
http://mail.python.org/mailman/listinfo/python-list