Add some cross-references to the docs. Simplify the python code equivalent for zip(). Supply an optional argument for the nth() recipe.

This commit is contained in:
Raymond Hettinger 2009-02-19 04:45:07 +00:00
parent d75fcb4ddf
commit cdf8ba369b
3 changed files with 16 additions and 11 deletions

View file

@ -1419,9 +1419,9 @@ Samuele
... "Return function(0), function(1), ..."
... return map(function, count(start))
>>> def nth(iterable, n):
... "Returns the nth item or None"
... return next(islice(iterable, n, None), None)
>>> def nth(iterable, n, default=None):
... "Returns the nth item or a default value"
... return next(islice(iterable, n, None), default)
>>> def quantify(iterable, pred=bool):
... "Count how many times the predicate is true"