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. 我觉得可使用random.shuffle
方法,可是当列表中包含对象时,这彷佛失败了。 Is there a method for shuffling objects or another way around this? 是否有一种用于改组对象的方法或解决此问题的另外一种方法? dom
import random class A: foo = "bar" a1 = a() a2 = a() b = [a1, a2] print(random.shuffle(b))
This will fail. 这将失败。 this