我有一个多变量函数,我想使用map()函数.
例:
def f1(a, b, c):
return a+b+c
map(f1, [[1,2,3],[4,5,6],[7,8,9]])
Run Code Online (Sandbox Code Playgroud)
rec*_*dev 10
itertools.starmap 为此做的:
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]]))
Run Code Online (Sandbox Code Playgroud)
输出:
[6, 15, 24]
Run Code Online (Sandbox Code Playgroud)
你不能.使用包装器.
def func1(a, b, c):
return a+b+c
map((lambda x: func1(*x)), [[1,2,3],[4,5,6],[7,8,9]])
Run Code Online (Sandbox Code Playgroud)