[Python-checkins] cpython: Issue 16774: Add a new itertools recipe (suggested by Alexey Kachayev).
raymond.hettinger
python-checkins at python.org
Mon May 26 07:04:10 CEST 2014
http://hg.python.org/cpython/rev/2781fb146f4a
changeset: 90838:2781fb146f4a
user: Raymond Hettinger <python at rcn.com>
date: Sun May 25 22:03:56 2014 -0700
summary:
Issue 16774: Add a new itertools recipe (suggested by Alexey Kachayev).
files:
Doc/library/itertools.rst | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
--- a/Doc/library/itertools.rst
+++ b/Doc/library/itertools.rst
@@ -662,6 +662,11 @@
"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.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list