From: Raymond Hettinger Date: Mon, 9 Mar 2009 11:57:29 +0000 (+0000) Subject: Add consume() recipe to itertools docs. X-Git-Tag: v2.7a1~1883 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3496a89f27515f555fe730a7855114a39e7dec4c;p=python Add consume() recipe to itertools docs. --- diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index f68465a4a8..1e946b11b0 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)