[Python-ideas] OrderedDict.peekitem()

Neil Girdhar mistersheik at gmail.com
Tue Jul 7 00:04:22 CEST 2015


You can do indexing, insertion, and removal all in logarithmic time (which
is basically constant) by using a B-tree as the underlying data structure.
 (See e.g. the blist package.)

On Mon, Jul 6, 2015 at 5:59 PM, Eric Snow <ericsnowcurrently at gmail.com>
wrote:

> On Mon, Jul 6, 2015 at 3:30 PM, Neil Girdhar <mistersheik at gmail.com>
> wrote:
> > SortedDict (
> http://www.grantjenks.com/docs/sortedcontainers/sorteddict.html)
> > manages to support indexing.  Can OrderedDict do the same thing?
>
> Don't forget that, as the docs describe, an "OrderedDict is a dict
> that remembers the order that keys were first inserted".  While
> obviously there's an implicit sequence for that order, the focus is
> still on dict-ness with the sequence exposed through the normal
> mapping approach (iteration).  If you want to get sequence semantics
> then first unpack the order into a sequence type like list or tuple.
> Or use some other type than OrderedDict.
>
> Note that OrderedDict's view types are essentially just dict's view
> types with custom iteration.  Adding indexing to the views would
> complicate things and certainly would not be O(1) like you would
> expect indexing to be.
>
> -eric
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150706/d2821867/attachment.html>


More information about the Python-ideas mailing list