]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fixup itertools recipe to cover a corner case.
authorRaymond Hettinger <python@rcn.com>
Tue, 27 Jan 2009 06:38:00 +0000 (06:38 +0000)
committerRaymond Hettinger <python@rcn.com>
Tue, 27 Jan 2009 06:38:00 +0000 (06:38 +0000)
Doc/library/itertools.rst
Lib/test/test_itertools.py

index dd998f6962600ad8fa0dc394e55366f98a67b21b..871b0cb83a782f5232fab3b3171f57b8cda2a614 100644 (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:
index 0f1f695a2dff92e046d1d664efbe3f8b2ac4e3d9..a45e608170a3ea712ae94efa17cd7120813f57cc 100644 (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: