I want to use partial()
to build a function that only takes one argument,
so that I can pass it to some high-order functions (ex: map()
/filter()
):
>>> from operator import sub
>>> from functools import partial
>>> map(lambda x:sub(x, 5), [1,2,3])
[-4, -3, -2]
>>> help(sub)
Help on built-in function sub in module operator:
sub(...)
sub(a, b) -- Same as a - b.
>>> map(partial(sub, b=5), [1,2,3])
TypeError: sub() takes no keyword arguments
Is there some way to make sub()
(or any other built-in functions) support keyword arguments?