Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fa00796

Browse files
committed
Add consume() recipe to itertools docs.
1 parent 5fa5d4f commit fa00796

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

Doc/library/itertools.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,10 @@ which incur interpreter overhead.
615615
"Return function(0), function(1), ..."
616616
return map(function, count(start))
617617

618+
def consume(iterator, n):
619+
"Advance the iterator n-steps ahead. If n is none, consume entirely."
620+
collections.deque(islice(iterator, n), maxlen=0)
621+
618622
def nth(iterable, n, default=None):
619623
"Returns the nth item or a default value"
620624
return next(islice(iterable, n, None), default)

0 commit comments

Comments
 (0)