[issue45093] Add method to compare dicts accounting for order
Steven D'Aprano
report at bugs.python.org
Sat Sep 4 01:24:13 EDT 2021
Steven D'Aprano <steve+python at pearwood.info> added the comment:
> Another case is in round trip processing of JSON or YML.
Sorry for my ignorance, but I don't see how or why an unordered
comparison would help you with round-tripping JSON or YAML.
The order of key:value pairs in JSON is not guaranteed to be preserved,
so if you round-trip a dict to JSON back to a dict, and then use an
ordered comparison, you might wrongly think that they are unequal.
(I think that Python's JSON does preserve order, by default. But other
JSON encoders might not.)
> Other cases are where you would prefer an OrderedDict over a dict.
Then use an OrderedDict.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45093>
_______________________________________
More information about the Python-bugs-list
mailing list