python3 List/列表 随机取出元素

随机从List中取出元素,代码如下:

import random

list = ['a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g']
for i in range(5):
    some = random.sample(list , 3)
    print(some)

随机取出3个元素,取5次,结果如下
这里写图片描述

猜你喜欢

转载自blog.csdn.net/dangsh_/article/details/79306866