如何创建元组列表列表的笛卡尔积

问题描述 投票:0回答:1

我正在尝试完成列表列表的笛卡尔积。基本元素是元组。关于元组的某些东西似乎真的让人感到困惑。我尝试的产品越多,它就越会增加元组的老鼠嵌套。

这是我的代码

product

和我的输出

from itertools import product listOfListsOfTuples = [ [(1,2),], [(3,4),(5,6)] ] got = list(product(listOfListsOfTuples)) print('got :',got) wanted = [ [(1,2),(3,4)], [(1,2),(5,6)] ] print('wanted:',wanted)

也许我需要回到
got : [([(1, 2)],), ([(3, 4), (5, 6)],)] wanted: [[(1, 2), (3, 4)], [(1, 2), (5, 6)]]

循环并自己做?

    

python python-3.x cartesian-product
1个回答
0
投票

for

	
© www.soinside.com 2019 - 2024. All rights reserved.