Python 将有序list打乱随机排序

版权声明:本文为博主原创文章,欢迎转载,转载时请以超链接形式标明文章原始出处。 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

猜你喜欢

转载自blog.csdn.net/lilongsy/article/details/84715221