I have:
def f(x, y): return x**2 + y**2
def g(x, y): return x**3 + y**3
def h(x, y): return x**4 + y**4
And I'd like to make a new function:
def J(x, y):
return f(x,y)*g(x,y)*h(x,y)
However, I am unable to find a way to do this programmatically. That is, take something like:
myFunctions = [f,g,h]
and return a new function J which returns the product of f, g and h.
Another wrinkle is that while f, g and h will always have an identical number of arguments, that number could change. That is, they could all have could have five arguments instead of two.
Desired behaviour:
print(J(2, 2)) # 4096
EDIT
The number of functions in myFunctions is also arbitrary.
I thought this was implied in my question, but upon rereading it I see that I did not make that at all clear. My apologies.
Jasdef J(*args, **kwargs)instead? Do you need the parameters for any other reason?*argsto pass an optional number of positional arguments to your function.functools.reduce,operator.mul,functools.partialand other functional tooling in Python to do this. As other comments note, you can define arbitrary positional and keyword arguments easily.