What is a good way to define a function partial_k(f, k, args)that takes an arbitrary function fas input ( ftakes npositional arguments), a value k and a list of values n-1and returns a new function that freezes all arguments fexcept 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