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): > Etc > And then concatenate the results but also to no avail. > > Again, any shoves in the right direction would be greatly appreciated. > > Scott
for i in xrange(start, end): print i 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 http://docs.python.org/library/functions.html#xrange *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 <http://docs.python.org/library/itertools.html#module-itertools>module:islice(count(start,step),(stop-start+step-1+2*(step<0))//step). 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. -- DaveA _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
