mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
Add consume() recipe to itertools docs.
This commit is contained in:
parent
5fa5d4febd
commit
fa007965c8
1 changed files with 4 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue