mistersheik at gmail.com
Mon Jul 6 23:30:36 CEST 2015
to support indexing. Can OrderedDict do the same thing?
On Monday, July 6, 2015 at 10:49:44 AM UTC-4, Kale Kundert 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
> 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
> you would want to see what's on the queue without popping it right away.
> My proposal is to add a peekitem() method to OrderedDict. This method
> have the same signature and would return the same thing as popitem(), it
> wouldn't modify the data structure.
> P.S. There is already a way to peek at the last item an OrderedDict, but
> hides the intent of the code and you wouldn't think of it if you weren't
> familiar with python: next(reversed(ordered_dict))
> Python-ideas mailing list
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas