我试图想出一个 Python 脚本来查找两个列表元素的所有成对组合(不管它们的元素的相对数量)。例如,如果A = ["a", "b", "c"]和B = [1, 2],则可能的对组合从 B 中取 1 个元素,然后从 B 中取 2 个元素,依此类推,针对所有A 的元素是(没有重复):
(1, 'a')
(1, 'b')
(1, 'c')
(2, 'a')
(2, 'b')
(2, 'c')
[(1, 'a'), (2, 'a')]
[(1, 'a'), (2, 'b')]
[(1, 'a'), (2, 'c')]
[(1, 'b'), (2, 'a')]
[(1, 'b'), (2, 'b')]
[(1, 'b'), (2, 'c')]
[(1, 'c'), (2, 'a')]
[(1, 'c'), (2, 'b')]
[(1, 'c'), (2, 'c')]
如果A = ["a", "b", "c"]和B = [1, 2, 3],则前 43 种组合使用 B 的 1 个元素,然后使用 B 的 2 个元素,依此类推A 的元素应该是:
(1, 'a')
(1, 'b')
(1, 'c')
(2, 'a')
(2, 'b')
(2, 'c')
(3, 'a')
(3, 'b')
(3, 'c')
[(1, 'a'), (2, 'a')]
[(1, 'a'), (2, 'b')]
[(1, 'a'), (2, 'c')]
[(1, 'b'), (2, 'a')]
[(1, 'b'), (2, 'b')]
[(1, 'b'), (2, 'c')]
[(1, 'c'), (2, 'a')]
[(1, 'c'), (2, 'b')]
[(1, 'c'), (2, 'c')]
[(1, 'a'), (3, 'a')]
[(1, 'a'), (3, 'b')]
[(1, 'a'), (3, 'c')]
[(1, 'b'), (3, 'a')]
[(1, 'b'), (3, 'b')]
[(1, 'b'), (3, 'c')]
[(1, 'c'), (3, 'a')]
[(1, 'c'), (3, 'b')]
[(1, 'c'), (3, 'c')]
[(2, 'a'), (3, 'a')]
[(2, 'a'), (3, 'b')]
[(2, 'a'), (3, 'c')]
[(2, 'b'), (3, 'a')]
[(2, 'b'), (3, 'b')]
[(2, 'b'), (3, 'c')]
[(2, 'c'), (3, 'a')]
[(2, 'c'), (3, 'b')]
[(2, 'c'), (3, 'c')]
[(1, 'a'), (2, 'a'), (3, 'a')]
[(1, 'a'), (2, 'a'), (3, 'b')]
[(1, 'a'), (2, 'a'), (3, 'c')]
[(1, 'a'), (2, 'b'), (3, 'a')]
[(1, 'a'), (2, 'b'), (3, 'b')]
[(1, 'a'), (2, 'b'), (3, 'c')]
[(1, 'a'), (2, 'c'), (3, 'a')]
: : :
: : :
这是我尝试使用此处的代码所做的,
精慕HU
相关分类