> On Jul 25, 2018, at 8:23 PM, INADA Naoki <songofaca...@gmail.com> wrote:
> 
> On Thu, Jul 26, 2018 at 12:04 PM Zhao Lee <redstone-c...@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.


Raymond
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to