I have a simple question about lambda functions. I want to do a loop, in which every iteration defines a new lambda function based on a lambda function from the previous iteration.
f = lambda x: x**2
j=0
J=2
while j<J:
f2 = lambda x: 0.5*f(x)
f = f2
j+=1
I expect the result of f(3) to be 2.25 = 0.5*0.5*3**2. However, I get the following error:
RecursionError: maximum recursion depth exceeded
I thought lambda functions can be used flexibly like this. I suppose there is a known pythonic way of how to do this properly?