changeset: 90838:2781fb146f4a user: Raymond Hettinger date: Sun May 25 22:03:56 2014 -0700 files: Doc/library/itertools.rst description: Issue 16774: Add a new itertools recipe (suggested by Alexey Kachayev). diff -r dc353953ce8b -r 2781fb146f4a Doc/library/itertools.rst --- a/Doc/library/itertools.rst Sun May 25 18:28:39 2014 -0700 +++ b/Doc/library/itertools.rst Sun May 25 22:03:56 2014 -0700 @@ -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.