Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python *参数的Itertools_Python - Fatal编程技术网

Python *参数的Itertools

Python *参数的Itertools,python,Python,我想要一个函数来生成任意数量数组的叉积 # Code to generate cross product of 3 arrays M = [1, 1] N = [2, 3] K = [4, 5] for M, N, K in itertools.product(M, N, K) 如果我想引入一个使用*的函数,那么实现它的好方法是什么 我尝试了以下代码,但以错误结束:“TypeError:'内置函数或方法'对象不可编辑” 实际上,您可以在不使用辅助函数的情况下使用解包: import itert

我想要一个函数来生成任意数量数组的叉积

# Code to generate cross product of 3 arrays
M = [1, 1]
N = [2, 3]
K = [4, 5]
for M, N, K in itertools.product(M, N, K)
如果我想引入一个使用*的函数,那么实现它的好方法是什么

我尝试了以下代码,但以错误结束:
“TypeError:'内置函数或方法'对象不可编辑”


实际上,您可以在不使用辅助函数的情况下使用解包:

import itertools

L = [[1, 1],
     [2, 3],
     [4, 5]]

for x in itertools.product(*L):
    print(x)

只需解包
返回itertools.product(*输入)
import itertools

L = [[1, 1],
     [2, 3],
     [4, 5]]

for x in itertools.product(*L):
    print(x)