[Tutor] Range limited?

Sean 'Shaleh' Perry shalehperry@home.com
Sat, 28 Jul 2001 20:30:12 -0700 (PDT)


On 29-Jul-2001 fleet@teachout.org wrote:
> Just for fun, I imported the smallest of the RSA Challenge numbers into a
> file, then (looking for factors):
> 
> 
> Apparently python (5.2.1) doesn't much care for 84 digit ranges.  I
> couldn't get this to work until I shortened the range number to 8 digits.
> (I skipped from 10 digits to 8, so maybe 9 digits will also work).
> 
> Did I mess something up or is 'range' limited?
> 

range creates a list containing every number in the range requested, so you
just asked for a 1 gb list (or so).  xrange returns an object that acts like a
list of numbers but actually generates each number as it is requested by the
loop.  For loops of more than a few hundred, you probably should use xrange. 
In fact xrange should almost be used as a habit.