Translate this to python?

Heiko Wundram modelnine at bit-bukket.org
Fri Jan 6 11:01:37 EST 2006


Xavier Morel wrote:
> I think that xrange is also soon-to-be deprecated (xrange eats a little
> less memory and is slightly faster to _create_, but much slower to
> _iterate over_ than range)

It might be slower to iterate using xrange, but xrange certainly has its
place in Python... Try the following on your computer:

for x in range(10**10):
    print x

for x in xrange(10**10):
    print x

Tell me which one doesn't overflow your memory. ;-) And before you come
telling me that these constraints are articial, I've _written_ programs
that had to iterate over 2**24 (the set of 10.* IP addresses), and I most
certainly wouldn't have wanted the machines to contain 384+ MB of RAM just
to store the number objects that range creates.

--- Heiko.



More information about the Python-list mailing list