Mike Meyer wrote:
> > 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)
it was? of the following four solutions,
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 eleme
"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
--
http://mail.python.org/
On 5/6/05, Bill Mill <[EMAIL PROTECTED]> wrote:
> 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?
>
> Python 2.4 and greater:
ummm, make that 2.3 and grea
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?
Python 2.4 and greater:
for n, x in enumerate(lst):
print "iteration %d on element %s" % (n, x)
Earlier:
n = 0
Hello,
when I'm iterating through a list with:
for x in list:
how can I get the number of the current iteration?
Thx,
Florian
--
http://mail.python.org/mailman/listinfo/python-list