summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2009-03-09 11:55:25 (GMT)
committerRaymond Hettinger <python@rcn.com>2009-03-09 11:55:25 (GMT)
commitfa007965c8cf15a45bb38b3b7432c6df1949c43f (patch)
tree25bdf07faa3bda7a645dfd825e6f7bb32b230a7d
parent5fa5d4febda8ea7980c621ffd76224bf5d6e5e01 (diff)
downloadcpython-fa007965c8cf15a45bb38b3b7432c6df1949c43f.zip
cpython-fa007965c8cf15a45bb38b3b7432c6df1949c43f.tar.gz
cpython-fa007965c8cf15a45bb38b3b7432c6df1949c43f.tar.bz2
Add consume() recipe to itertools docs.
-rw-r--r--Doc/library/itertools.rst4
1 files changed, 4 insertions, 0 deletions
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
index 8855a46..2c79b06 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)