diff options
author | Raymond Hettinger <python@rcn.com> | 2003-05-02 19:04:37 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2003-05-02 19:04:37 (GMT) |
commit | 14ef54cd833c7ccfa0b3d03e2b45074d54a8ac87 (patch) | |
tree | e21099b898f9374f4b0082e68cd1ab53a8c1530a /Doc | |
parent | e2df5ffa539bc1d903684e8c5863645a8886bfe2 (diff) | |
download | cpython-14ef54cd833c7ccfa0b3d03e2b45074d54a8ac87.zip cpython-14ef54cd833c7ccfa0b3d03e2b45074d54a8ac87.tar.gz cpython-14ef54cd833c7ccfa0b3d03e2b45074d54a8ac87.tar.bz2 |
SF bug #730685: itertools.islice stop argument is not optional
* itertools.islice() stop argument did not perform as documented.
* beefed-up test suite
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/lib/libitertools.tex | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/Doc/lib/libitertools.tex b/Doc/lib/libitertools.tex index 93116ea..d0e1269 100644 --- a/Doc/lib/libitertools.tex +++ b/Doc/lib/libitertools.tex @@ -197,9 +197,9 @@ by functions or loops that truncate the stream. If \var{start} is non-zero, then elements from the iterable are skipped until start is reached. Afterward, elements are returned consecutively unless \var{step} is set higher than one which results in items being - skipped. If \var{stop} is specified, then iteration stops at the - specified element position; otherwise, it continues indefinitely or - until the iterable is exhausted. Unlike regular slicing, + skipped. If \var{stop} is not specified or is \code{None}, then iteration + continues indefinitely; otherwise, it stops at the specified position. + Unlike regular slicing, \function{islice()} does not support negative values for \var{start}, \var{stop}, or \var{step}. Can be used to extract related fields from data where the internal structure has been flattened (for @@ -208,17 +208,20 @@ by functions or loops that truncate the stream. \begin{verbatim} def islice(iterable, *args): - s = slice(*args) - next = s.start or 0 - stop = s.stop - step = s.step or 1 + if args: + s = slice(*args) + next = s.start or 0 + stop = s.stop + step = s.step or 1 + else: + next, stop, step = 0, None, 1 for cnt, element in enumerate(iterable): if cnt < next: continue - if cnt >= stop: + if stop is not None and cnt >= stop: break yield element - next += step + next += step \end{verbatim} \end{funcdesc} @@ -360,7 +363,7 @@ from building blocks. >>> def pairwise(seq): ... "s -> (s0,s1), (s1,s2), (s2, s3), ..." -... return izip(seq, islice(seq,1,len(seq))) +... return izip(seq, islice(seq,1,None)) >>> def padnone(seq): ... "Returns the sequence elements and then returns None indefinitely" |