Suppose I have function, f
, which takes in some variable and returns a variable of the same type. For simplicity, let's say
def f(x):
return x/2+1
I'm interested in applying f
to itself over and over. Something like f(f(f(...(f(x))...)))
.
I could do this like
s = f(x)
for i in range(100):
s = f(s)
But I was wondering if there was a simpler, less verbose way to doing the same thing. I wan't to avoid for
loops (just as a challenge to myself). Is there maybe some way of using map
or a similar function to accomplish this?