From: Raymond Hettinger Date: Sun, 27 Mar 2005 20:16:49 +0000 (+0000) Subject: SF patch #1171417: bug fix for islice() in docs X-Git-Tag: v2.4.1~12 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ec113af0de457e11e564598c61e2e6312f393ecb;p=thirdparty%2FPython%2Fcpython.git SF patch #1171417: bug fix for islice() in docs --- diff --git a/Doc/lib/libitertools.tex b/Doc/lib/libitertools.tex index be53015f7cd9..b62bd87c918e 100644 --- a/Doc/lib/libitertools.tex +++ b/Doc/lib/libitertools.tex @@ -252,14 +252,12 @@ by functions or loops that truncate the stream. \begin{verbatim} def islice(iterable, *args): s = slice(*args) - next, stop, step = s.start or 0, s.stop, s.step or 1 - for cnt, element in enumerate(iterable): - if cnt < next: - continue - if stop is not None and cnt >= stop: - break - yield element - next += step + it = iter(xrange(s.start or 0, s.stop or sys.maxint, s.step or 1)) + nexti = it.next() + for i, element in enumerate(iterable): + if i == nexti: + yield element + nexti = it.next() \end{verbatim} \end{funcdesc}