Trying to use sets for random selection, but the pop() method returns items in order
Mario Garcia
Mariosky at gmail.com
Thu Jul 2 09:27:36 EDT 2009
This could be better:
>>> import random
>>> population = range(10)
>>> choice = random.choice(population)
>>> population.remove(choice)
>>> print population
>>> print population
[0, 1, 2, 3, 4, 5, 6, 8, 9]
That was my idea with the previous pop(), remove from the population a
certain number of elements at random.
In the docs pop is defined as:
Remove and return an arbitrary element from the set.
My mistake: arbitrary is not the same as random :(
Mario
More information about the Python-list
mailing list