就像在标题中一样,我想洗牌命令的顺序,
a = [print("something"),print("another_thing")]
import random
random.shuffle(a)
for i in a:
print(i)
最简单的方法是使用lambda:
comms = [lambda: print("something"), lambda: print("another_thing")]
重新洗牌:
random.shuffle(comms)
然后调用项目(并收集结果):
results = list(comm() for comm in comms)