From fa007965c8cf15a45bb38b3b7432c6df1949c43f Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Mon, 9 Mar 2009 11:55:25 +0000 Subject: Add consume() recipe to itertools docs. --- Doc/library/itertools.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index 8855a46..2c79b06 100644 --- a/Doc/library/itertools.rst +++ b/Doc/library/itertools.rst @@ -615,6 +615,10 @@ which incur interpreter overhead. "Return function(0), function(1), ..." return map(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) -- cgit v0.12