<div dir="ltr">SortedDict (http://www.grantjenks.com/docs/sortedcontainers/sorteddict.html) manages to support indexing.  Can OrderedDict do the same thing?<br><br>On Monday, July 6, 2015 at 10:49:44 AM UTC-4, Kale Kundert wrote:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">Today I was trying to use collections.OrderedDict to manage a LIFO queue, and I
<br>was surprised to realize that OrderedDict doesn't provide a way to look at its
<br>first or last item.  There is an OrderedDict.popitem() method, which removes and
<br>returns either the first or last item, but it's not hard to imagine cases where
<br>you would want to see what's on the queue without popping it right away.
<br>
<br>My proposal is to add a peekitem() method to OrderedDict.  This method would
<br>have the same signature and would return the same thing as popitem(), it just
<br>wouldn't modify the data structure.
<br>
<br>-Kale
<br>
<br>P.S. There is already a way to peek at the last item an OrderedDict, but it
<br>hides the intent of the code and you wouldn't think of it if you weren't
<br>familiar with python: next(reversed(ordered_dict))
<br>
<br>______________________________<wbr>_________________
<br>Python-ideas mailing list
<br><a href="javascript:" target="_blank" gdf-obfuscated-mailto="abf6XHw7PkgJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">Python...@python.org</a>
<br><a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank" rel="nofollow" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Fpython-ideas\46sa\75D\46sntz\0751\46usg\75AFQjCNFj1EaNHnVmh20FnFPoUi4J-MpfQw';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Fpython-ideas\46sa\75D\46sntz\0751\46usg\75AFQjCNFj1EaNHnVmh20FnFPoUi4J-MpfQw';return true;">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a>
<br>Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank" rel="nofollow" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fpython.org%2Fpsf%2Fcodeofconduct%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNHJOrArSUDKkjrnthO6_CznMzkPsA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fpython.org%2Fpsf%2Fcodeofconduct%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNHJOrArSUDKkjrnthO6_CznMzkPsA';return true;">http://python.org/psf/<wbr>codeofconduct/</a>
<br></blockquote></div>