Re: Getting number of iteration

2005-05-06 Thread Fredrik Lundh
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,

Re: Getting number of iteration

2005-05-06 Thread Mike Meyer
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

Re: Getting number of iteration

2005-05-06 Thread George Sakkis
"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/

Re: Getting number of iteration

2005-05-06 Thread Bill Mill
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

Re: Getting number of iteration

2005-05-06 Thread Bill Mill
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

Getting number of iteration

2005-05-06 Thread Florian Lindner
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