diff options
author | Raymond Hettinger <python@rcn.com> | 2009-02-19 05:34:35 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2009-02-19 05:34:35 (GMT) |
commit | f9bce83e71c07ccd7b0ae1a75ea6912f0023b802 (patch) | |
tree | 5457b11a6eef3f2efc6f36368ee0eb3d13118193 /Doc/library/itertools.rst | |
parent | 182edaefb515ece87d225494d79ccf7dd35d1ec1 (diff) | |
download | cpython-f9bce83e71c07ccd7b0ae1a75ea6912f0023b802.zip cpython-f9bce83e71c07ccd7b0ae1a75ea6912f0023b802.tar.gz cpython-f9bce83e71c07ccd7b0ae1a75ea6912f0023b802.tar.bz2 |
Add some cross-references to the docs. Simplify the python code equivalent for izip(). Supply an optional argument for the nth() recipe.
Diffstat (limited to 'Doc/library/itertools.rst')
-rw-r--r-- | Doc/library/itertools.rst | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index 6fa1978..299d769 100644 --- a/Doc/library/itertools.rst +++ b/Doc/library/itertools.rst @@ -427,8 +427,7 @@ loops that truncate the stream. # izip('ABCD', 'xy') --> Ax By iterables = map(iter, iterables) while iterables: - result = [it.next() for it in iterables] - yield tuple(result) + yield yield tuple(map(next, iterables)) .. versionchanged:: 2.4 When no iterables are specified, returns a zero length iterator instead of @@ -702,9 +701,9 @@ which incur interpreter overhead. "Return function(0), function(1), ..." return imap(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" |