1. 程式人生 > >Python 將有序list打亂隨機排序

Python 將有序list打亂隨機排序

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