python sample

sample(序列a,n)

功能:从序列a中随机抽取n个元素,并将n个元素生以list形式返回。

from random import randint, sample
date = [randint(10,20) for _ in range(10)]
c = sample(date, 5)
print(c)
# 输出:[12, 17, 10, 12, 17]

  randint(10,20) for _ in range(10):从10~20间随机抽取10个数;

posted @ 2020-08-21 15:03  柒久酒  阅读(490)  评论(0编辑  收藏  举报