From: Raymond Hettinger Date: Mon, 9 Mar 2009 11:58:33 +0000 (+0000) Subject: Add consume() recipe to itertools docs. X-Git-Tag: v2.6.2c1~109 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fb30cca59127475a10c0961cf660d85c035ed7ee;p=thirdparty%2FPython%2Fcpython.git Add consume() recipe to itertools docs. --- diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index baa3566edfaf..d4d130fea6d6 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)