[Python-Dev] enumerate with a start index
Josiah Carlson
jcarlson at uci.edu
Thu Oct 20 01:28:29 CEST 2005
Michel Pelletier <michel at cignex.com> wrote:
>
> Martin Blais wrote:
> > Hi
> >
> > Just wondering, would anyone think of it as a good idea if the
> > enumerate() builtin could accept a "start" argument? I've run across
> > a few cases where this would have been useful. It seems generic
> > enough too.
>
> +1, but something more useful might be a a cross between enumerate a
> zip, where you pass N iterables and it yields N-tuples. Then you could
> do something like:
>
> zipyield(range(10, 20), mygenerator())
>
> and it would be like you wanted for enumerate, but starting from 10 in
> this case.
All of this already exists.
from itertools import izip, count
for i,j in izip(count(start), iterable):
...
Read your standard library.
- Josiah
More information about the Python-Dev
mailing list