[Tutor] Range limited?
fleet@teachout.org
fleet@teachout.org
Mon, 30 Jul 2001 11:16:18 -0400 (EDT)
Thanks for the pointer to xrange. I circumvented the problem by switching
to "while i < [long(sqrt(target number))]: " I set a print command to
print 'i' in multiples of 10,000. About 10 hours later I had hit a
billion (10 digits). Hmmmm, 74 digits to go! :) I think not.
(Actually, I investigated primes a little and after finding that the
200,000th prime number is only 7 digits long, I pretty much decided I
can't run with the big dogs - so I'll just stay on the porch!) :)
- fleet -
PS: Should the above be
"while long(i) < upper-bound-of-many-digit-number"?
Will "i" go flaky after 16 digits or is it sufficient that only one number
be long?
On Sat, 28 Jul 2001, Sean 'Shaleh' Perry wrote:
> On 29-Jul-2001 fleet@teachout.org wrote:
> > 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.
>