Commit 928713c7 authored by Raymond Hettinger's avatar Raymond Hettinger

Correct the docs for takewhile(). Improve the recipe for nth(). Should be backported

parent 5a3b524e
...@@ -117,7 +117,7 @@ by functions or loops that truncate the stream. ...@@ -117,7 +117,7 @@ by functions or loops that truncate the stream.
Make an iterator that drops elements from the iterable as long as Make an iterator that drops elements from the iterable as long as
the predicate is true; afterwards, returns every element. Note, the predicate is true; afterwards, returns every element. Note,
the iterator does not produce \emph{any} output until the predicate the iterator does not produce \emph{any} output until the predicate
is true, so it may have a lengthy start-up time. Equivalent to: first becomes false, so it may have a lengthy start-up time. Equivalent to:
\begin{verbatim} \begin{verbatim}
def dropwhile(predicate, iterable): def dropwhile(predicate, iterable):
...@@ -509,8 +509,8 @@ def iteritems(mapping): ...@@ -509,8 +509,8 @@ def iteritems(mapping):
return izip(mapping.iterkeys(), mapping.itervalues()) return izip(mapping.iterkeys(), mapping.itervalues())
def nth(iterable, n): def nth(iterable, n):
"Returns the nth item or raise IndexError" "Returns the nth item or raise StopIteration"
return list(islice(iterable, n, n+1))[0] return islice(iterable, n, None).next()
def all(seq, pred=None): def all(seq, pred=None):
"Returns True if pred(x) is true for every element in the iterable" "Returns True if pred(x) is true for every element in the iterable"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment