[Tutor] List all possible 10digit number
eryksun at gmail.com
Sat Sep 1 11:08:50 CEST 2012
On Sat, Sep 1, 2012 at 3:18 AM, Dave Angel <d at davea.name> wrote:
> Somehow i missed the point that xrange() is NOT necessarily limited to
> Python int values. So it may be usable on your machine, if your Python
> is 64bit. All I really know is that it works on mine (2.7 64bit, on
> Linux). See the following quote
Since xrange uses a C long type, it's limited to sys.maxint. On a
64-bit Linux system a C long is 64-bit. In Windows, a C long is always
32-bit, so I would suppose sys.maxint is 2**31 - 1 on both 32-bit and
64-bit systems. Someone running 64-bit Windows can confirm that.
Or more commonly with step==1:
islice(count(start), stop - start)
This works so long as the 2nd argument is less than sys.maxsize. On my
32-bit system, that's limited to 2**31 - 1. So instead I decided to
slice a billion numbers at a time and use chain.from_iterable() to
chain several slices from a generator expression.
Previously I thought it had to be less than sys.maxint. The error on
my 32-bit Debian system said the value had to be <= maxint, so I
assumed islice uses a C long type. But I looked in the
itertoolsmodule.c source (2.7.3) and discovered that islice uses a C
ssize_t. So the error should have said the size has to be <= maxsize.
On a 64-bit platform that's 2**63 - 1, even on 64-bit Windows. Again,
someone running 64-bit Windows can confirm that.
More information about the Tutor