Python 2.7 range Function provokes a Memory Error

2QdxY4RzWzUUiLuE at potatochowder.com 2QdxY4RzWzUUiLuE at potatochowder.com
Thu Mar 2 06:34:24 EST 2023


On 2023-03-02 at 11:25:49 +0000,
Stephen Tucker <stephen_tucker at sil.org> wrote:

> The range function in Python 2.7 (and yes, I know that it is now
> superseded), provokes a Memory Error when asked to deiliver a very long
> list of values.
> 
> I assume that this is because the function produces a list which it then
> iterates through.
> 
> 1. Does the  range  function in Python 3.x behave the same way?

No.

> 2. Is there any equivalent way that behaves more like a  for loop (that is,
> without producing a list)?

Try xrange.


More information about the Python-list mailing list