From: Raymond Hettinger Date: Mon, 9 Mar 2009 11:55:25 +0000 (+0000) Subject: Add consume() recipe to itertools docs. X-Git-Tag: v3.1a2~297 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fa007965c8cf15a45bb38b3b7432c6df1949c43f;p=thirdparty%2FPython%2Fcpython.git Add consume() recipe to itertools docs. --- diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index 8855a4616c8a..2c79b06c9dff 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)