1-liner to iterate over infinite sequence of integers?

Paul Rubin http
Fri Oct 14 01:30:17 CEST 2005


Steven D'Aprano <steve at REMOVETHIScyber.com.au> writes:
> Others have given answers involving xrange() and itertools.count(), but I
> thought I'd just mention that in my opinion, what you have written is
> pretty elegant and concise and best of all, doesn't have the same problems
> xrange() and itertools.count() have when then hit maxint. Not everything
> needs to be a one-liner or a mysterious blackbox.

When you say "problems" with xrange or itertools.count hitting maxint,
the correct word is "bugs".  The right thing to do with library bugs
is fix them, not clutter up your application code to circumvent them.
xrange, at least, raises an error if you give it too large an
argument, but what itertools.count does is just plain dangerous.

I just opened SF bug 1326277 about itertools.count.



More information about the Python-list mailing list