Whrandom

Duncan Smith buzzard at urubu.freeserve.co.uk
Mon May 14 21:03:49 EDT 2001


I would do the following.

>>> import whrandom
>>> dict = {}
>>> while len(dict.keys()) != 5:
...  dict[whrandom.randint(1, 1000)] = None
...
>>> dict.keys()
[247, 844, 578, 892, 244]

Now I am a statistician and not a computer scientist.  I have developed a
habit of using dictionaries (as above) rather than lists because I am under
the impression it is more efficient than checking the current list for a
match on each iteration.  Could any computer scientists out there confirm
this (or point me in a more efficient direction).  Cheers.

Duncan





More information about the Python-list mailing list