random
模块下的shuffle
函数就可以打乱list
。
from random import shuffle
l = [1, 2, 3, 4, 5]
shuffle(l)
print(l)
# [2, 3, 4, 5, 1]
参考:https://docs.python.org/3/library/random.html?highlight=random#random.shuffle
Python 将有序list打乱随机排序
阅读 48
2022-07-12
random
模块下的shuffle
函数就可以打乱list
。
from random import shuffle
l = [1, 2, 3, 4, 5]
shuffle(l)
print(l)
# [2, 3, 4, 5, 1]
参考:https://docs.python.org/3/library/random.html?highlight=random#random.shuffle
相关推荐
精彩评论(0)