Fixup itertools recipe to cover a corner case.

This commit is contained in:
Raymond Hettinger 2009-01-27 06:38:00 +00:00
parent badbba4f99
commit cdc9f2c1d5
2 changed files with 4 additions and 0 deletions

View File

@ -686,6 +686,8 @@ which incur interpreter overhead.
# number items returned: (n+r-1)! / r! / (n-1)!
pool = tuple(iterable)
n = len(pool)
if not n and r:
return
indices = [0] * r
yield tuple(pool[i] for i in indices)
while 1:

View File

@ -1268,6 +1268,8 @@ Samuele
... "combinations_with_replacement('ABC', 3) --> AA AB AC BB BC CC"
... pool = tuple(iterable)
... n = len(pool)
... if not n and r:
... return
... indices = [0] * r
... yield tuple(pool[i] for i in indices)
... while 1: