diff options
Diffstat (limited to 'itertoolset.py')
-rw-r--r-- | itertoolset.py | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/itertoolset.py b/itertoolset.py index eb96e74..2d71d0c 100644 --- a/itertoolset.py +++ b/itertoolset.py @@ -3,20 +3,21 @@ import collections from copy import deepcopy 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` times `nreps`. This iterator - is safe even if the item consumer modifies the items. + """Returns an iterator that emits each element of `i` multiple times + specified by `nreps`. The length of this iterator is the lenght of `i` + times `nreps`. This iterator is safe even if the item consumer modifies + the items. - >>> list(repeating_iterator('ABCD', 3) - ['A', 'A', 'A', 'B', 'B', 'B', 'C', 'C', 'C', 'D', 'D', 'D'] - >>> list(repeating_iterator('ABCD', 1) - ['A', 'B', 'C', 'D'] - ''' + Examples: + >>> list(repeating_iterator('ABCD', 3) + ['A', 'A', 'A', 'B', 'B', 'B', 'C', 'C', 'C', 'D', 'D', 'D'] + >>> list(repeating_iterator('ABCD', 1) + ['A', 'B', 'C', 'D'] + """ for item in i: for counter in xrange(nreps): yield deepcopy(item) - def grouper(n, iterable, fillvalue=None): "grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx" args = [iter(iterable)] * n |