产品在python中做什么?
如何更换?
它的功能是什么?
*
标志有什么作用?
如何在不获取生成器警告消息的情况下进行测试
<itertools.product object at 0x0159BD00>
答案 0 :(得分:5)
它计算Cartesian product超过任意数量的iterables。 Source
因此,如果您有两个列表,例如[1,2]
和[3,4]
,则笛卡尔积为(1,3),(1,4),(2,3),(2,4)
答案 1 :(得分:2)
尝试迭代它:
for p in itertools.product((1,2,3), (4,5,6)):
print p
产生
(1, 4)
(1, 5)
(1, 6)
(2, 4)
(2, 5)
(2, 6)
(3, 4)
(3, 5)
(3, 6)
答案 2 :(得分:1)
你检查过Python itertools.product docs了吗?它计算笛卡尔积:
itertools.product(* iterables [,repeat])输入的笛卡尔积 iterables。
等效于生成器表达式中的嵌套for循环。例如, 对于B中的y,product(A,B)返回与(x,y)中的x相同的返回值。
您是否有关于此的具体问题?