]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add consume() recipe to itertools docs.
authorRaymond Hettinger <python@rcn.com>
Mon, 9 Mar 2009 11:55:25 +0000 (11:55 +0000)
committerRaymond Hettinger <python@rcn.com>
Mon, 9 Mar 2009 11:55:25 +0000 (11:55 +0000)
Doc/library/itertools.rst

index 8855a4616c8a2246a813359f7a514f2d82b4bc5c..2c79b06c9dffda6e36a97fde261dcc527245e23d 100644 (file)
@@ -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)