What is the best way to get all but the last N elements of an iterator in Python? Here is an example of it in theoretical action:
>>> list(all_but_
Use a collections.deque. Push N items from the source on the first invocation. On each subsequent invocation, pop an item out, push an item in from the source, and yield the popped item.
N