In latest python version, dict retains the order of insertion. Is there any change in terms of equality. For example, currently the below works. Since insertion order will be important, can this change in future?
I am asking because there is fundamental change - previously == worked because insertion order was not important as it was considered un-ordered. Now since it is ordered, can the meaning of equality change?
d1={'a':1,'b':2}
d2={'b':2,'a':1}
print(d1==d2)
True
l1=['a','b']
l2=['b','a']
print(l1==l2)
False
Python's official documentation states the following about the == operator regarding dictionaries:
Mappings (instances of dict) compare equal if and only if they have equal (key, value) pairs. Equality comparison of the keys and values enforces reflexivity.
So, insertion order is not considered, and due to backwards compatibility, it probably never will be, as it probably wouldn't make sense, or be unintuitive, in almost all cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With