]> 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:56:52 +0000 (11:56 +0000)
committerRaymond Hettinger <python@rcn.com>
Mon, 9 Mar 2009 11:56:52 +0000 (11:56 +0000)
Doc/library/itertools.rst

index 16a0fa9638fc2499848dae08abb98dcfc40b1c01..91aa09bb237de68bc7be22c62cb5d6d9f8e90fba 100644 (file)
@@ -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)