版权声明:本文为博主原创文章,欢迎转载,转载时请以超链接形式标明文章原始出处。 https://blog.csdn.net/lilongsy/article/details/84715221
random
模块下的shuffle
函数就可以打乱list
。
from random import shuffle
l = [1, 2, 4, 5]
shuffle(l)
print(l)
# [2, 3, 4, 5, 1]
参考:https://docs.python.org/3/library/random.html?highlight=random#random.shuffle