summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony LaTorre <tlatorre9@gmail.com>2011-08-26 19:10:10 -0400
committerAnthony LaTorre <tlatorre9@gmail.com>2011-08-26 19:10:10 -0400
commitdd4085d7ca49bbde2826192716c1aa7c69b4bcc6 (patch)
tree599027bb00a26bdafa81cdc1f140d8a550231bc5
parent41ffc05d05bfa3849c8160dd7cfa95b1eb51bb61 (diff)
downloadchroma-dd4085d7ca49bbde2826192716c1aa7c69b4bcc6.tar.gz
chroma-dd4085d7ca49bbde2826192716c1aa7c69b4bcc6.tar.bz2
chroma-dd4085d7ca49bbde2826192716c1aa7c69b4bcc6.zip
add repeat_func() to itertoolset.
-rw-r--r--itertoolset.py9
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`