我将如何生成2个列表的每一个可能组合



所以我会有两个列表,其中包含随机数量的值。例如:

listx = [15513, 813, 984949, 5000], listj = [76815, 75, 8484, 9419419, 418841814, 84848, 84848]

我将如何生成这些列表的每一个可能的组合?类似:

combination = [15513, 75, 9419419]

它可以从两个列表中取任意多的值来用于组合,我想检查每一个组合,就像它可以从第一个中取2个值,从另一个中取5个值,或者全部从第一个取3个值。

TRY:

from itertools import combinations, chain
listx = [15513, 813, 984949, 5000]
listj = [76815, 75, 8484, 9419419, 418841814, 84848, 84848]
for i in range(2, len(listx) + len(listj)):
print(list(combinations(chain(*[listx,listj]), i)))

最新更新