Shuffling a list of objects

后端 未结 23 1689
眼角桃花
眼角桃花 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:03

    It took me some time to get that too. But the documentation for shuffle is very clear:

    shuffle list x in place; return None.

    So you shouldn't print(random.shuffle(b)). Instead do random.shuffle(b) and then print(b).

提交回复
热议问题