Issue 16774: Add a new itertools recipe (suggested by Alexey Kachayev).

This commit is contained in:
Raymond Hettinger 2014-05-25 22:03:56 -07:00
parent 2d452ee166
commit dfe098d215
1 changed files with 5 additions and 0 deletions

View File

@ -662,6 +662,11 @@ which incur interpreter overhead.
"Return function(0), function(1), ..."
return map(function, count(start))
def tail(n, iterable):
"Return an iterator over the last n items"
# tail(3, 'ABCDEFG') --> E F G
return iter(collections.deque(iterable, maxlen=n))
def consume(iterator, n):
"Advance the iterator n-steps ahead. If n is none, consume entirely."
# Use functions that consume iterators at C speed.