Shuffling a list of objects

后端 未结 23 1691
眼角桃花
眼角桃花 2020-11-22 00:29

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

23条回答
  •  孤街浪徒
    2020-11-22 01:12

    import random
    class a:
        foo = "bar"
    
    a1 = a()
    a2 = a()
    b = [a1.foo,a2.foo]
    random.shuffle(b)
    

提交回复
热议问题