How to include insertion order in dict equality

Terry Reedy tjreedy at udel.edu
Fri Sep 3 22:32:29 EDT 2021


In https://bugs.python.org/issue45093, Michael Rans suggested adding a 
dict method that would include the insertion order in comparing dicts 
for equality. He wanted this for testing.  The proposal is rejected 
because there are already multiple good methods.  To make them more 
visible and searchable, I list them here.

Steven D'Aprano:
d1 == d2 and all(k1 == k2 for k1, k2 in zip(d1, d2))

Sethiy Storchaka:
list(d1.items()) == list(d2.items())
# When using unittest, produces nicer report on failure.

Raymond Hettinger:
assert OrderedDict(d) == OrderedDict(e)

-- 
Terry Jan Reedy



More information about the Python-list mailing list