Kaydet (Commit) dfe098d2 authored tarafından Raymond Hettinger's avatar Raymond Hettinger

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

üst 2d452ee1
...@@ -662,6 +662,11 @@ which incur interpreter overhead. ...@@ -662,6 +662,11 @@ which incur interpreter overhead.
"Return function(0), function(1), ..." "Return function(0), function(1), ..."
return map(function, count(start)) 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): def consume(iterator, n):
"Advance the iterator n-steps ahead. If n is none, consume entirely." "Advance the iterator n-steps ahead. If n is none, consume entirely."
# Use functions that consume iterators at C speed. # Use functions that consume iterators at C speed.
......
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