itertools.count() as built-in

Alex Martelli aleax at mac.com
Sun May 28 20:04:31 EDT 2006


jantod at gmail.com <jantod at gmail.com> wrote:

> I have a project of around 6000 lines where I used count() 20 times. It
> has 14 modules, 10 of which I needed an explicit import.
> 
> Many of the usages are of the form:
> 
> for item, n in zip(items, count(N)):
>  dostuff
> 
> Around half of these are due to using pylab.subplot(x,y.n), which
> requires values for n>=1. So I want N=1. The enumerate builtin starts
> from 0.

Hmmm, makes me wonder if enumerate should grow optional arguments for
starting and stepping... I've found myself in similar situations, using
"x*i+y" on the i returned by enumerate, or zipping an xrange instead...


Alex



More information about the Python-list mailing list