like this?
for i in range(nIterations): y = f(y)
A for loop with one command can be written as a single line.
EDIT
Or maybe slightly cleaner:
for _ in xrange(nIterations): y = f(y)
Since you don't want to have a something that can be split into two separate statements (i think), here's another one:
reduce(lambda y, _: f(y), xrange(nIterations), initValue)
Still, I would recommend to just use your original code, which is much more intuitive and readable. Also note what Guido van Rossum has to say on loops versus repeat
.
Note by the way that (in python 2.x) xrange
is more efficient than range
for large nIterations as it returns an actual iterator and not an allocated list.