所以我有这些清单:
a = [1, 2, 3]
b = [11, 12, 13, 14]
c = [21, 22, 23, 24, 25, 26]
Run Code Online (Sandbox Code Playgroud)
我希望获得所有可能的组合(重复都很好),包括来自的a3个元素b和来自3个元素的2 个元素c.像这样:
([1, 2], [11, 12, 13], [21, 22, 23]) # 1
([1, 2], [11, 12, 13], [22, 23, 24]) # 2
# all the way to...
([2, 3], [12, 13, 14], [24, 25, 26]) # 16
Run Code Online (Sandbox Code Playgroud)
如果我使用itertools.product(),它只给我每个列表1:
import itertools
def cartesian(the_list):
for i in itertools.product(*the_list):
yield i
a = [1, …Run Code Online (Sandbox Code Playgroud)