Question: I'm trying to write a function in python that is like:

```
def repeated(f, n):
    ...

```

where `f` is a function that takes one argument and `n` is a positive integer.

For example if I defined square as:

```
def square(x):
    return x * x

```

and I called

```
repeated(square, 2)(3)

```

this would square 3, 2 times.

Answer: 
Using reduce and itertools.repeat (as Marcin suggested):

```
from itertools import repeat
from functools import reduce # necessary for python3

def repeated(func, n):
    def apply(x, f):
        return f(x)
    def ret(x):
        return reduce(apply, repeat(func, n), x)
    return ret

```

You can use it as follows:

```
>>> repeated(os.path.dirname, 3)('/a/b/c/d/e/f')
'/a/b/c'

>>> repeated(square, 5)(3)
1853020188851841

```

(after importing `os` or defining `square` respectively)
I think you want function composition:

```
def compose(f, x, n):
  if n == 0:
    return x
  return compose(f, f(x), n - 1)

def square(x):
  return pow(x, 2)

y = compose(square, 3, 2)
print y

```