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