对于长度为 n 的数值列表,例如[1, 3, 1, 2, ...]
,我想创建一个列表的列表,其中包含所有可能的值组合,range[x+1]
其中 x 是列表中的一个值。输出可能如下所示:
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, e2, e3]
from的所有变体e1 in [0,1], e2 in [0,1,2,3] and e3 in [0,1,2]