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]])
itertools.starmap made for this:
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]]))
Conclusion:
[6, 15, 24]
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]])
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]])
Source: https://habr.com/ru/post/907631/More articles:Check the time of an existing PendingIntent in AlarmManager - javaLimited generics with hierarchy in type parameter - genericsHamcrest CombinableMatcher - general method will not compile - javaResizing a window using OpenGL and SDL - sdlFile Card Processing in C ++ - c ++Bash Shell list files using the for loop - bashHow to get the current page URL in asp.net using the code behind the technique? - urlreceive broadcast when sd card unmount android - androidfunction as parameter vs function pointer as parameter - c ++JavaScript generation from JSLINT parsing tree - javascriptAll Articles