3 ms·
question: does the following expression still evaluate to True with ordered dicts? {'a':1, 'b':2} == {'b':2, 'a':1}
by diN0bot 7y ago
question: does the following expression still evaluate to True with ordered dicts?
{'a':1, 'b':2} == {'b':2, 'a':1}
- ebg13 7y agoYes. Dict comparison doesn't rely on iteration order.
- diN0bot 7y agothanks :-) i mean, i would hope not if it's an implementation detail and not a change in the abstraction itself... feels a bit like it is breaking the abstraction, though.
- ebg13 7y agoThe definition of a dict hasn't changed. It's still defined as a set of key:value pairs. It just happens to also have a particular guarantee now that iterating over the keys will return them in insertion order.
- diN0bot 7y agonevermind, i thought this was a future change, but it's already live. i've been using 3.7.4, and can confirm that two dictionaries with equivalent key,value pairs, even if inserted in a different order, are considered abstractly equal. this coincidentally came up for me this morning on a small interview challenge: https://dev.to/candidateplanet/comment/l8o2 https://dev.to/candidateplanet/comment/l8o2