sample, choices: 从list中随机选择无重复的元素
from random import sample mylist = ['python', 'c++', 'html', 'CSS', 'JavaScript'] print(sample(mylist, k=4))
使用choices会有重复,而使用sample,则不会出现重复。
来源:https://stackoverflow.com/questions/70565925/how-to-disable-duplicated-items-in-random-choice