[issue9823] OrderedDict is comparable to dict

Raymond Hettinger report at bugs.python.org
Fri Sep 10 20:20:46 CEST 2010


Raymond Hettinger <rhettinger at users.sourceforge.net> added the comment:

That is the documented and tested behavior:  http://docs.python.org/library/collections.html#ordereddict-objects

"""
Equality tests between OrderedDict objects are order-sensitive and are implemented as list(od1.items())==list(od2.items()). Equality tests between OrderedDict objects and other Mapping objects are order-insensitive like regular dictionaries. This allows OrderedDict objects to be substituted anywhere a regular dictionary is used.
"""

It was a basic design objective for OrderedDicts to be substitutable for regular dictionaries (that is why it subclasses from dict).  This lets an OD be used just about anywhere in Python where a regular dict is expected.

Also look at:  http://en.wikipedia.org/wiki/Liskov_substitution_principle

----------
assignee:  -> rhettinger
nosy: +rhettinger

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9823>
_______________________________________


More information about the Python-bugs-list mailing list