Message 65810 - Python tracker (original) (raw)
What are the use cases for ranges with length greater than maxsize?
Yeah---I'm a bit short on use cases. The one that originally bit me with Python 2.x was when I was doing a search for a quadratic non-residue modulo a largeish prime;
for i in range(1, p): if (i_is_a_nonresidue_modulo_p): break
Here p might be a 200-digit prime number, and the situation is that half the integers between 1 and p-1 are 'quadratic residues', while the other half are 'quadratic nonresidues'; in practice the residues and nonresidues are mixed up fairly well, so the first nonresidue shows up pretty quickly, but there's no known small upper bound on when the first nonresidue appears.
Of course, it's not hard to rewrite this with a while loop instead; it would just be a bit annoying if that were necessary, when the code above is so clear and direct, and the one obvious way to do it (TM).
I'd also note that it's not completely out of the question that something like range(1010) would be useful on a 32-bit machine: a long-running process might easily go through 1010 iterations of something.
I agree it's a bit strange to have a semi-functional range object, that you can iterate over but not take the length of.