diff options
author | Raymond Hettinger <python@rcn.com> | 2009-03-09 11:58:33 +0000 |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2009-03-09 11:58:33 +0000 |
commit | fb30cca59127475a10c0961cf660d85c035ed7ee (patch) | |
tree | 765273f21bbcbc4f70ff55a93491482d37eeb206 | |
parent | d31d294e894eb13f0fb1b6185c4e9d0b928fa224 (diff) | |
download | cpython-git-fb30cca59127475a10c0961cf660d85c035ed7ee.tar.gz |
Add consume() recipe to itertools docs.
-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 baa3566edf..d4d130fea6 100644 --- a/Doc/library/itertools.rst +++ b/Doc/library/itertools.rst @@ -635,6 +635,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) |