Using a display function with a multi-variable function

I have a function with several variables, and I would like to use the map () function with it.

Example:

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

itertools.starmap made for this:

 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]])) 

Conclusion:

 [6, 15, 24] 
+10
source

You can not. Use a wrapper.

 def func1(a, b, c): return a+b+c map((lambda x: func1(*x)), [[1,2,3],[4,5,6],[7,8,9]]) 
+5
source

You can simply wrap your function with several arguments inside another function, which takes only one argument as a tuple / list, and then passes it to the inner function.

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

Source: https://habr.com/ru/post/907631/


All Articles