Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.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 将map函数与多变量函数结合使用_Python_Dictionary - Fatal编程技术网

Python 将map函数与多变量函数结合使用

Python 将map函数与多变量函数结合使用,python,dictionary,Python,Dictionary,我有一个多变量函数,我想使用map()函数 例如: def f1(a, b, c): return a+b+c map(f1, [[1,2,3],[4,5,6],[7,8,9]]) 你不能。使用包装器 def func1(a, b, c): return a+b+c map((lambda x: func1(*x)), [[1,2,3],[4,5,6],[7,8,9]]) 您可以简单地将多参数函数包装到另一个函数中,该函数只将一个参数作为元组/列表,然后将其传递给内部函数

我有一个多变量函数,我想使用map()函数

例如:

def f1(a, b, c):
    return a+b+c
map(f1, [[1,2,3],[4,5,6],[7,8,9]])

你不能。使用包装器

def func1(a, b, c):
    return a+b+c

map((lambda x: func1(*x)), [[1,2,3],[4,5,6],[7,8,9]])

您可以简单地将多参数函数包装到另一个函数中,该函数只将一个参数作为元组/列表,然后将其传递给内部函数

map(lambda x: func(*x), [[1,2,3],[4,5,6],[7,8,9]])
为此而制作:

import itertools

def func1(a, b, c):
    return a+b+c

print list(itertools.starmap(func1, [[1,2,3],[4,5,6],[7,8,9]]))
输出:

[6, 15, 24]