How to make python built-in functions support keyword arguments?
functional-programming, python
Solution
If a function defined in C does not take keyword arguments then there is no way to force it to do so. Either use `lamdba` and fill the arguments in the hard way, or wrap the function in a Python function that can take keyword arguments.
Problem
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?