diff options
author | Raymond Hettinger <python@rcn.com> | 2009-01-27 06:38:00 +0000 |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2009-01-27 06:38:00 +0000 |
commit | cdc9f2c1d573a4ae96ac592c303f7f443a704859 (patch) | |
tree | 70226b9147394c271500f32ec4af56edcb2b5200 | |
parent | badbba4f99c13e8ebc804ec0f404665a3d89fc11 (diff) | |
download | cpython-git-cdc9f2c1d573a4ae96ac592c303f7f443a704859.tar.gz |
Fixup itertools recipe to cover a corner case.
-rw-r--r-- | Doc/library/itertools.rst | 2 | ||||
-rw-r--r-- | Lib/test/test_itertools.py | 2 |
2 files changed, 4 insertions, 0 deletions
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index dd998f6962..871b0cb83a 100644 --- a/Doc/library/itertools.rst +++ b/Doc/library/itertools.rst @@ -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: diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py index 0f1f695a2d..a45e608170 100644 --- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -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: |