diff options
-rw-r--r-- | itertoolset.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/itertoolset.py b/itertoolset.py index 2d71d0c..8d94e14 100644 --- a/itertoolset.py +++ b/itertoolset.py @@ -2,6 +2,15 @@ from itertools import * import collections from copy import deepcopy +def repeat_func(func, times=None, args=()): + "equivalent to (func(*args) for i in xrange(times))." + if times is None: + while True: + yield func(*args) + else: + for i in xrange(times): + yield func(*args) + def repeating_iterator(i, nreps): """Returns an iterator that emits each element of `i` multiple times specified by `nreps`. The length of this iterator is the lenght of `i` |