How to construct such a functional-programming tool in Python?

Viewed 168

I want a function named times(), in order to make:

times(func,2) equivalent to lambda x:func(func(x))

and times(func,5) equivalent to lambda x:func(func(func(func(func(x)))))

Is there such a tool in Python? What would the code looks like if I want to write it by myself?

Thanks!

2 Answers
Related