列表的可能结果

时间:2014-06-13 17:15:35

标签: python

我有可能分[0,1,2]。如何列出从5个回合中的样本列表中创建0-10分的所有可能方法

例如:

score 0: score 0,0,0,0,0
score 1: score 00001, 00010, 00100, 01000, 10000 ....
...
...

不确定如何处理此问题

我认为这是一个排列问题,我使用set 0,1,2生成5个数字的排列

1 个答案:

答案 0 :(得分:8)

我想你想要itertools.product

print list(itertools.product([0, 1, 2], repeat=5))