python-small-examples

@author jackzhenguo
@desc 
@date 2019/5/1

81 shuffle 重洗数据集

使用shuffle用来重洗数据集,值得注意shuffle是对lst就地(in place)洗牌,节省存储空间。

from random import shuffle
lst = [randint(0,50) for _ in range(100)]
shuffle(lst)
print(lst[:5]) # [50, 3, 48, 1, 26]
[上一个例子](/python-small-examples/md/80.html) [下一个例子](/python-small-examples/md/82.html)