Commit fa007965 authored by Raymond Hettinger's avatar Raymond Hettinger

Add consume() recipe to itertools docs.

parent 5fa5d4fe
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment