[Python-ideas] OrderedDict.peekitem()

Mark Lawrence breamoreboy at yahoo.co.uk
Mon Jul 6 23:06:14 CEST 2015

On 06/07/2015 16:38, Paul Sokolovsky wrote:
> Hello,
> On Mon, 06 Jul 2015 07:39:58 -0700
> Kale Kundert <kale at thekunderts.net> wrote:
>> Today I was trying to use collections.OrderedDict to manage a LIFO
>> queue, and I was surprised to realize that OrderedDict doesn't
>> provide a way to look at its first or last item.  There is an
>> OrderedDict.popitem() method, which removes and returns either the
>> first or last item, but it's not hard to imagine cases where you
>> would want to see what's on the queue without popping it right away.
> What's wrong with using list, collections.Deque, heapq to manage a LIFO
> queue?

Or queue.LifoQueue or even multiprocessing.Queue depending on the 
precise requirements?

My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

More information about the Python-ideas mailing list