diff options
author | Raymond Hettinger <python@rcn.com> | 2009-03-09 11:57:29 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2009-03-09 11:57:29 (GMT) |
commit | 3496a89f27515f555fe730a7855114a39e7dec4c (patch) | |
tree | baf7a07ae23f8b664362c150effcb82dc06ece1a /Doc/library/itertools.rst | |
parent | fed84c765d85b6a0492f0b36df638bce1614764d (diff) | |
download | cpython-3496a89f27515f555fe730a7855114a39e7dec4c.zip cpython-3496a89f27515f555fe730a7855114a39e7dec4c.tar.gz cpython-3496a89f27515f555fe730a7855114a39e7dec4c.tar.bz2 |
Add consume() recipe to itertools docs.
Diffstat (limited to 'Doc/library/itertools.rst')
-rw-r--r-- | Doc/library/itertools.rst | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index f68465a..1e946b1 100644 --- a/Doc/library/itertools.rst +++ b/Doc/library/itertools.rst @@ -701,6 +701,10 @@ which incur interpreter overhead. "Return function(0), function(1), ..." return imap(function, count(start)) + def consume(iterator, n): + "Advance the iterator n-steps ahead. If n is none, consume entirely." + collections.deque(islice(iterator, n), maxlen=0) + def nth(iterable, n, default=None): "Returns the nth item or a default value" return next(islice(iterable, n, None), default) |