Lists and Indices

Jim Meier jim at dsdd.org
Fri Aug 9 10:32:24 CEST 2002


On Fri, 09 Aug 2002 02:16:20 -0600, Duncan Booth wrote:
> Cleaner would just be to use enumerate from the PEP:
> 
>     from __future__ import generators
>     def enumerate(collection):
>         'Generates an indexed series:  (0,coll[0]), (1,coll[1]) ...'     
>         i = 0
>         it = iter(collection)
>         while 1:
>             yield (i, it.next())
>             i += 1
> 
> When Python 2.3 comes along you can just delete all of the above for the 
> same effect.

Yum. Thanks for the pointer :)

-Jim



More information about the Python-list mailing list