[Tutor] Why does counting to 20 million stress my computer?

Eric at Zomething eric at zomething.com
Sat Jul 17 22:04:47 CEST 2004

Danny Yoo <dyoo at hkn.eecs.berkeley.edu> wrote:

> In this case, range() is a good tool for this job, because it gives us a
> list that we can munge up with random.shuffle().  xrange() gives us just
> an iterable that's specialized only to do sequential counting, so it
> wouldn't be as appropriate here.

Can anyone suggest how I might make the following a bit more efficient in terms of RAM usage (without having to do any additional file operations)?

nixList=completedNumbers    # a list constructed from pickled data on file
for x in random.Random().sample(xrange(maxNumber),maxSample):
    if (str(x) not in nixList):
        # do a bunch of processing
        # pickle numbers successfully processed for later reference in nixList


Eric Pederson
e-mail me at:
do at something.com
except, increment the "d" and "o" by one letter
and spell something with a "z"

More information about the Tutor mailing list