def compose(f, g):
return lambda x:f(g(x))
def thrice(f):
return compose(f, compose(f, f))
add1 = lambda x: x + 1
print(thrice(thrice)(add1)(6)) = 33
Can anyone explain to me why is this 33? which side of the composite function should i start reading?
thrice(thrice)takes a function and returns the same function composited 3^3=27 times. Hence,thrice(thrice)(add1)is a function that adds 27 to its input. Calling it with 6 returns 33.