您可以使用random.sample
为此,从文档:
返回从总体序列中选择的 k 长度的唯一元素列表。用于无放回随机抽样。
并重复该过程n_times
使用列表理解:
n_times = 100
n_sample = 3
[random.sample(test, n_sample) for i in range(n_times)]
[['llama', 'goat', 'sheep'],
['cat', 'horse', 'dog'],
['sheep', 'dog', 'goat'],
['cat', 'cow', 'llama'],
['dog', 'fish', 'horse'],
['llama', 'horse', 'cow'],
['dog', 'goat', 'cow'],
['llama', 'cow', 'sheep'],
['fish', 'dog', 'horse'],
...