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?
2. Is there any equivalent way that behaves more like a for loop (that is, without producing a list)?
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?
2. Is there any equivalent way that behaves more like a for loop (that is, without producing a list)?
Hi,
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?
2. Is there any equivalent way that behaves more like a for loop (that is, without producing a list)?
To get round the problem I have written my own software that is used in a
for loop.
On 2023-03-02, Stephen Tucker <[email protected]> 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, in Python 3 it is an iterator which produces the next number in the sequence each time.
2. Is there any equivalent way that behaves more like a for loop (thatis,
without producing a list)?
Yes, 'xrange' in Python 2 behaves like 'range' in Python 3.
--
https://mail.python.org/mailman/listinfo/python-list
Hi again,
I tried xrange, but I got an error telling me that my integer was too big
for a C long.
Clearly, xrange in Py2 is not capable of dealing with Python (that is, possibly very long) integers.
I am raising this because,
(a) IF xrange in Py3 is a simple "port" from Py2, then it won't handle
Python integers either.
AND
(b) IF xrange in Py3 is intended to be equivalent to range (which, even in Py2, does handle Python integers)
THEN
It could be argued that xrange in Py3 needs some attention from the developer(s).
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 145:02:43 |
| Calls: | 12,089 |
| Calls today: | 2 |
| Files: | 15,000 |
| Messages: | 6,517,496 |