0

The map function is good way to parallelly compute function values. When the function has keyword parameters, how to use the map? For example:

def func(a, b=0, c=0):

    print a, b, c

Sometimes, kwargs is convenient to pass parameters to function, ignoring the argument sequence to call. Can map function can be used like this?

map(func, range(3), c=[1, 3, 5])

However, it would be TypeError.

TypeError: map() takes no keyword arguments

Is there any simple way to continue use map() with keyword arguments?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Ryan
  • 235
  • 3
  • 5
  • You need to use [`functools.partial`](https://docs.python.org/3/library/functools.html#functools.partial) to create a single-argument callable with those keyword arguments preset. – jonrsharpe Apr 07 '17 at 09:09
  • Maybe lambda expression would be useful here. map(lamda x: func(x, c=[1, 3, 5]), range(3)) – Patrik Polakovic Apr 07 '17 at 10:21

0 Answers0