What is a good way to define a function partial_k(f, k, args)
that takes an arbitrary function f
as input ( f
takes n
positional arguments), a value k and a list of values n-1
and returns a new function that freezes all arguments f
except the kth argument?
For example:
def f(a, b, c):
return (a, b, c)
assert partial_k(f, 2, [0, 1])(10) == (0, 1, 10)
assert partial_k(f, 1, [0, 1])(10) == (0, 10, 1)
I could only find very verbose ways to do this.
source
share