I ran into an error when using partial
from the functools
library.
from functools import partial
def add(x,a,b):
return x + 10*a + 100*b
add = partial(add, x=2, b=3)
print (add(4))
I get the error:
TypeError: add() got multiple values for argument 'x'
I know that this can be fixed by bringing forward a
to the first positional argument of add
like:
def add(b,a,x):
return x + 10*a + 100*b
add = partial(add, x=2, a=3)
print (add(4))
which correctly gives out: 432
My question is whether there is a way to keep the order of x,a,b intact within the add
function and altering the partial
function to give out the correct result. This is important because something like the add
function is used elsewhere and so it is important for me to keep the order in the original add
function intact.
I don't want to use a keyword argument with the function like print (add(a = 4))
because I want it as an input to a map function
For example I want to do something like this:
print (list(map(add,[1,2,3])))
print (min([1,2,3], key = add)))