[Tutor] Why does counting to 20 million stress my computer?
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Fri Jul 16 19:21:28 CEST 2004
> Try replacing "range(max)" with "xrange(max)".
> No need for a degree, just read the manual:
> http://docs.python.org/lib/built-in-funcs.html
Hi Dick,
An alternative solution is to use a while-loop, something like:
###
counter = 0
while counter < 10:
print "counter is:", counter
counter = counter + 1
###
Using range() on large numbers is a common gotcha, so don't worry too much
about not knowing about xrange(). There are a few things that work
perfectly well on small things, but break down when the problem grows much
larger; range() is one of those.
Good luck to you!
More information about the Tutor
mailing list