<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>On Jul 6, 2015, at 14:30, Neil Girdhar <<a href="mailto:mistersheik@gmail.com">mistersheik@gmail.com</a>> wrote:</div><div><br></div><blockquote type="cite"><div><div dir="ltr">SortedDict (<a href="http://www.grantjenks.com/docs/sortedcontainers/sorteddict.html">http://www.grantjenks.com/docs/sortedcontainers/sorteddict.html</a>) manages to support indexing.  </div></div></blockquote><div><br></div><div>Only by having a special view, accessed as .index. If it just took indices as subscripts, that would be ambiguous with integer keys.</div><br><blockquote type="cite"><div><div dir="ltr">Can OrderedDict do the same thing?<br></div></div></blockquote><div><br></div><div>It's worth noting that most of the various different sorted containers on PyPI support something equivalent, but all with different interfaces.</div><div><br></div><div>More importantly, they all use logarithmic data structures (binary trees, b-trees, skip lists, the hybrid thing blist uses, ...), which give you O(log N) indexing, and some of them can do even better by giving you O(log N) to find a slice and O(1) within that slice; OrderedDict uses a linked list, so it would be O(N).</div><br><blockquote type="cite"><div><div dir="ltr"><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></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Python-ideas mailing list</span><br><span><a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a></span><br><span><a href="https://mail.python.org/mailman/listinfo/python-ideas">https://mail.python.org/mailman/listinfo/python-ideas</a></span><br><span>Code of Conduct: <a href="http://python.org/psf/codeofconduct/">http://python.org/psf/codeofconduct/</a></span></div></blockquote></body></html>