diff options
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/itertools.rst | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index 3cef985..5d3593e 100644 --- a/Doc/library/itertools.rst +++ b/Doc/library/itertools.rst @@ -675,17 +675,17 @@ which incur interpreter overhead. filtered = ifilter(operator.itemgetter(1), decorated) return imap(operator.itemgetter(0), filtered) - def combinations_with_replacement(iterable, r): - "combinations_with_replacement('ABC', 3) --> AA AB AC BB BC CC" - pool = tuple(iterable) - n = len(pool) - indices = [0] * r - yield tuple(pool[i] for i in indices) - while 1: - for i in reversed(range(r)): - if indices[i] != n - 1: - break - else: - return - indices[i:] = [indices[i] + 1] * (r - i) - yield tuple(pool[i] for i in indices) + def combinations_with_replacement(iterable, r): + "combinations_with_replacement('ABC', 3) --> AA AB AC BB BC CC" + pool = tuple(iterable) + n = len(pool) + indices = [0] * r + yield tuple(pool[i] for i in indices) + while 1: + for i in reversed(range(r)): + if indices[i] != n - 1: + break + else: + return + indices[i:] = [indices[i] + 1] * (r - i) + yield tuple(pool[i] for i in indices) |