pythonic way to do something N times without an index variable? [duplicate]

A slightly faster approach than looping on xrange(N) is:

import itertools

for _ in itertools.repeat(None, N):
    do_something()

Leave a Comment