我知道如何通过将两个函数作为输入并输出其组合函数来组合两个函数,但是如何返回组合函数f(f(... f(x)))呢?谢谢
def compose2(f, g):
return lambda x: f(g(x))
def f1(x):
return x * 2
def f2(x):
return x + 1
f1_and_f2 = compose2(f1, f2)
f1_and_f2(1)
Run Code Online (Sandbox Code Playgroud)