[Tutor] List all possible 10digit number
d at davea.name
Sat Sep 1 09:18:03 CEST 2012
On 08/31/2012 09:08 PM, Scurvy Scott wrote:
> First of all thank you guys for all your help. The manual is really no substitute for having things explained in laymans terms as opposed to a technical manual.
> My question is this- I've been trying for a month to generate a list of all possible 10 digit numbers. I've googled, looked on stackoverflow, experimented with itertools, lists, etc to no avail. The closest I've gotten is using itertools to generate every possible arrangement of a list
> List = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
> I feel like I'm close but can't quite get it. Any suggestions or shoves in the right direction would be helpful. An issue I've encountered is that python won't do something like
> For I in range(1000000000, 9999999999):
> Print I
> Without crashing or throwing an exception.
> I've also tried to do something like
> I in range (100, 900):
> And then concatenate the results but also to no avail.
> Again, any shoves in the right direction would be greatly appreciated.
for i in xrange(start, end):
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 from
*CPython implementation detail:*xrange()
<http://docs.python.org/library/functions.html#xrange>is intended to be
simple and fast. Implementations may impose restrictions to achieve
this. The C implementation of Python restricts all arguments to native C
longs (“short” Python integers), and also requires that the number of
elements fit in a native C long. If a larger range is needed, an
alternate version can be crafted using theitertools
Anyway, if you're not sure that xrange() will work for your particular
range of values, then use
current = 10**9
lim = 10**10
while current < lim:
print current #or write to file, or whatever
current += 1
or use the combination of islice and count listed above.
More information about the Tutor