[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Python-Dev] [issue34221] Any plans to combine collections.OrderedDict with dict

> On Jul 25, 2018, at 8:23 PM, INADA Naoki <songofacandy at gmail.com> wrote:
> On Thu, Jul 26, 2018 at 12:04 PM Zhao Lee <redstone-cold at 163.com> wrote:
>> Since Python 3.7?dicts remember the order that items were inserted, so any plans to combine collections.OrderedDict with dict?
>> https://docs.python.org/3/library/collections.html?#collections.OrderedDict
>> https://docs.python.org/3/library/stdtypes.html#dict
> No.  There are some major difference.
> * d1 == d2 ignores order / od1 == od2 compares order
> * OrderedDict has move_to_end() method.
> * OrderedDict.pop() takes `last=True` keyword.

In addition to the API differences noted by Naoki, there are also implementation differences.  The regular dict implements a low-cost solution for common cases.  The OrderedDict has a more complex scheme that can handle frequent rearrangements (move_to_end operations) without touching, resizing, or reordering the underlying dictionary. Roughly speaking, regular dicts emphasize fast, space-efficient core dictionary operations over ordering requirements while OrderedDicts prioritize ordering operations over other considerations.

That said, now that regular dicts are ordered by default, the need for collections.OrderedDict() should diminish quite a bit.  Mostly, I think people will ignore OrderedDict unless their application heavily exercises move to end operations.