Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
__eq__ on a dict
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Steven D'Aprano, post: 1828476"] Replying to myself... how sad. On reading it, that came across more snarky than I intended. Sorry. However, I wasn't completely insane, since I came across this tidbit: [URL]http://python.active-venture.com/ref/comparisons.html[/URL] "Mappings (dictionaries) compare equal if and only if their sorted (key, value) lists compare equal. Outcomes other than equality are resolved consistently, but are not otherwise defined." with a footnote leading to this comment: "Earlier versions of Python used lexicographic comparison of the sorted (key, value) lists, but this was very expensive for the common case of comparing for equality." I also suggested: I certainly can't prove it, since my example pseudo-code fails even on the example I used earlier. Sigh. In summary: Equality of dicts is guaranteed. Two dicts are equal if and only if their keys:value pairs are equal. Other orderings between dicts are calculated consistently but not in any documented way. One gotcha is that some dicts are unordered: py> {1:1j} < {1:2j} Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: cannot compare complex numbers using <, <=, >, >= but even that is special-cased up to the wazzoo: py> {1:1j} < {1:1j} False [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
__eq__ on a dict
Top