python 将有序list打乱

利用random模块下的shuffle函数就可以实现

>>> temp = [i for i in range(8)]
>>> temp
[0, 1, 2, 3, 4, 5, 6, 7]
>>> import random
>>> random.shuffle(temp)
>>> temp
[5, 2, 0, 7, 1, 4, 3, 6]

posted @ 2017-10-08 22:44  kennyhip  阅读(134)  评论(0)    收藏  举报