From: Raymond Hettinger Date: Mon, 26 May 2014 05:03:56 +0000 (-0700) Subject: Issue 16774: Add a new itertools recipe (suggested by Alexey Kachayev). X-Git-Tag: v3.5.0a1~1594 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dfe098d2150b4dc2842a15c6c30438effb40c0b7;p=thirdparty%2FPython%2Fcpython.git Issue 16774: Add a new itertools recipe (suggested by Alexey Kachayev). --- diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index 1f0bcedc0a4e..c5ba2eb5960c 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.