Idiomatic Python: 'times' loop

Posted by perimosocordiae on Stack Overflow See other posts from Stack Overflow or by perimosocordiae
Published on 2010-04-17T03:09:14Z Indexed on 2010/04/17 3:13 UTC
Read the original article Hit count: 361

Filed under:
|
|

Say I have a function foo that I want to call n times. In Ruby, I would write:

n.times { foo }

In Python, I could write:

for _ in xrange(n): foo()

But that seems like a hacky way of doing things.

My question: Is there an idiomatic way of doing this in Python?

© Stack Overflow or respective owner

Related posts about python

Related posts about loops