python-small-examples/md/81.md at master · data-python/python-small-examples

Latest commit

File metadata and controls

16 lines (13 loc) · 340 Bytes

@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]