From dd4085d7ca49bbde2826192716c1aa7c69b4bcc6 Mon Sep 17 00:00:00 2001 From: Anthony LaTorre Date: Fri, 26 Aug 2011 19:10:10 -0400 Subject: add repeat_func() to itertoolset. --- itertoolset.py | 9 +++++++++ 1 file changed, 9 insertions(+) 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` -- cgit