From a5b0e9a565e96a74852a53accc47c3831b8b6d9a Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Mon, 9 Mar 2009 11:56:52 +0000 Subject: [PATCH] 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 16a0fa9638fc..91aa09bb237d 100644 --- a/Doc/library/itertools.rst +++ b/Doc/library/itertools.rst @@ -549,6 +549,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) -- 2.47.3