summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2014-05-26 05:03:56 (GMT)
committerRaymond Hettinger <python@rcn.com>2014-05-26 05:03:56 (GMT)
commitdfe098d2150b4dc2842a15c6c30438effb40c0b7 (patch)
tree29c115343133e903ff4a6623abf1b3b617d3859e
parent2d452ee166c15002cdb70fab69dc654aac5db0a0 (diff)
downloadcpython-dfe098d2150b4dc2842a15c6c30438effb40c0b7.zip
cpython-dfe098d2150b4dc2842a15c6c30438effb40c0b7.tar.gz
cpython-dfe098d2150b4dc2842a15c6c30438effb40c0b7.tar.bz2
Issue 16774: Add a new itertools recipe (suggested by Alexey Kachayev).
-rw-r--r--Doc/library/itertools.rst5
1 files changed, 5 insertions, 0 deletions
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
index 1f0bced..c5ba2eb 100644
--- a/Doc/library/itertools.rst
+++ b/Doc/library/itertools.rst
@@ -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.