It should be a very basic question but I wonder what's the most pythonic way to handle high order function. I have f
and g
already defined:
def f(x):
return x**2
def g(x):
return x**3
def gen_func(f,g):
def func(x):
return f(x)+g(x)
return func
wanted_func = gen_func(f, g)
or:
import functools
def gen_func(f,g,x):
return f(x)+g(x)
wanted_func = functools.partial(gen_func, f, g)
And there may be a point I could miss where these two writing differ?