simulate enumerate in python 2.1
Terry Reedy
tjreedy at udel.edu
Mon Jul 10 14:01:26 EDT 2006
<eight02645999 at yahoo.com> wrote in message
news:1152549048.932608.301130 at m79g2000cwm.googlegroups.com...
> hi,
> i am using python 2.1. Can i use the code below to simulate the
> enumerate() function in 2.3? If not, how to simulate in 2.1?
> thanks
>
> from __future__ import generators
> def enumerate(sequence):
> index = 0
> for item in sequence:
> yield index, item
> index += 1
Didn't generators and the new iterator protocol arrived in 2.2?
If so you have to write an iterator in the older __getitem__ protocol,
which should be in the 2.1 docs.
tjr
More information about the Python-list
mailing list