我将如何生成 2 个列表的所有可能组合
How would I generate every possible combination of 2 lists
所以我会有 2 个列表,其中的值数量是随机的。
例如:
listx = [15513, 813, 984949, 5000], listj = [76815, 75, 8484, 9419419, 418841814, 84848, 84848]
我将如何生成这些列表的所有可能组合?
喜欢:
combination = [15513, 75, 9419419]
它可以从两个列表中获取尽可能多的值以用于组合,我想检查每个组合,比如它可以从第一个中获取 2 个值,从另一个中获取 5 个值,或者全部从第一个和另一个的 3 个。
尝试:
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)))
所以我会有 2 个列表,其中的值数量是随机的。 例如:
listx = [15513, 813, 984949, 5000], listj = [76815, 75, 8484, 9419419, 418841814, 84848, 84848]
我将如何生成这些列表的所有可能组合? 喜欢:
combination = [15513, 75, 9419419]
它可以从两个列表中获取尽可能多的值以用于组合,我想检查每个组合,比如它可以从第一个中获取 2 个值,从另一个中获取 5 个值,或者全部从第一个和另一个的 3 个。
尝试:
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)))