Range() limit

Erik Max Francis max at alcyone.com
Fri Feb 21 20:35:57 EST 2003


Marc wrote:

> I have a quick question on the limits of the range() function. This is
> probably computer speed and memory dependent, but is there any value
> over which the range function can't handle. I'm doing iterations over
> quite a large range, and as it approaches 50 million potential
> iterations it stalls and dies.
> 
> Have I exceeded Python's ability to handle iterations or is a
> limitation with my computer.

range _actually builds a list_.  If the number of elements in that list
is huge, you're going to be building a really big list.  If you're using
it solely for the purposes of iterating over, obviously this ain't the
brightest idea in the world.  Use xrange instead, or simply count
manually.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ There are defeats more triumphant than victories.
\__/ Montaigne
    Python chess module / http://www.alcyone.com/pyos/chess/
 A chess game adjudicator in Python.




More information about the Python-list mailing list