有關n長度的數值列表,例如: G。 [1, 3, 1, 2, ...]
,我想創建一個列表,其中x是列表中的一個值,其值爲range[x+1]
的所有可能組合的列表。輸出可能是這個樣子:Python:如何從一系列數字範圍創建組合列表
for list[1, 3, 2] return all possible lists of range[x+1] values:
# the sequence of the list is unimportant
[
[0,0,0],[1,0,0],[0,1,0],[0,2,0],[0,3,0],[0,0,1],[0,0,2],[1,1,0],
[1,2,0],[1,3,0],[1,0,1],[1,0,2],[0,1,1],[0,2,1],[0,3,1],[0,1,2],
[0,2,2],[0,3,2],[1,1,1],[1,2,1],[1,3,1],[1,1,2],[1,2,2],[1,3,2]
]
因此,在這個例子中,我從e1 in [0,1], e2 in [0,1,2,3] and e3 in [0,1,2]
尋找的[e1, e2, e3]
所有變化
什麼是'x'在你的榜樣?長度列表'x = 3'? –
@Yuval看到有問題的添加評論 – Cole