You could use functools.partial()
:
from functools import partial
map(partial(add_x_to_input, some_value_for_x), myList)
or you could use a lambda
(an anonymous, in-line function):
map(lambda k: add_x_to_input(some_value_for_x, k), myList)
or you could define an explicit new function:
def wrapping_function(k):
return add_x_to_input(some_value_for_x, k)
map(wrapping_function, myList)
If you are after sheer speed, the functools.partial()
approach wins that hands-down; it is implemented in C code and avoids an extra Python stack push:
>>> import timeit
>>> L = range(10)
>>> def foo(a, b): pass
...
>>> def p(b): return foo(1, b)
...
>>> timeit.timeit('map(p, L)', 'from __main__ import foo, L; from functools import partial; p = partial(foo, 1)')
3.0008959770202637
>>> timeit.timeit('map(p, L)', 'from __main__ import foo, L; p = lambda b: foo(1, b)')
3.8707590103149414
>>> timeit.timeit('map(p, L)', 'from __main__ import foo, L, p')
3.9136409759521484