Mailing List Archive

How to include insertion order in dict equality
In, 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