python指定随机几个
random.sample()
# 使用 比如随机2个
import random
newlist = random.sample([1,2,3,4,5,6],2)
样例
import random
newlist = random.sample([1,2,3,4,5,6],2)
print(newlist)
list = {'11','22','33','44'}
newlisttwo = random.sample(list,2)
print(newlisttwo)
listtwo = ['0:{name:李白,}','1:{name:杜甫,}','2:{name:辛弃疾,}']
newlistthree = random.sample(listtwo,2)
print(newlistthree)