I have a list of objects and I want to shuffle them. I thought I could use the random.shuffle
method, but this seems to fail when the list is of objects. Is the
It works fine. I am trying it here with functions as list objects:
from random import shuffle
def foo1():
print "foo1",
def foo2():
print "foo2",
def foo3():
print "foo3",
A=[foo1,foo2,foo3]
for x in A:
x()
print "\r"
shuffle(A)
for y in A:
y()
It prints out: foo1 foo2 foo3 foo2 foo3 foo1 (the foos in the last row have a random order)