]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
SF patch #1171417: bug fix for islice() in docs
authorRaymond Hettinger <python@rcn.com>
Sun, 27 Mar 2005 20:16:49 +0000 (20:16 +0000)
committerRaymond Hettinger <python@rcn.com>
Sun, 27 Mar 2005 20:16:49 +0000 (20:16 +0000)
Doc/lib/libitertools.tex

index be53015f7cd979020b7a134aaab93c8068d54e9b..b62bd87c918e4c42a2472336648ede4aec2b6c99 100644 (file)
@@ -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}