From: Raymond Hettinger Date: Tue, 27 Jan 2009 06:38:00 +0000 (+0000) Subject: Fixup itertools recipe to cover a corner case. X-Git-Tag: v2.6.2c1~235 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cdc9f2c1d573a4ae96ac592c303f7f443a704859;p=thirdparty%2FPython%2Fcpython.git Fixup itertools recipe to cover a corner case. --- diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index dd998f696260..871b0cb83a78 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 0f1f695a2dff..a45e608170a3 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: