|
|
Log in / Subscribe / Register

Hashable mappings

Hashable mappings

Posted Dec 6, 2025 5:23 UTC (Sat) by iabervon (subscriber, #722)
In reply to: Hashable mappings by AdamW
Parent article: A "frozen" dictionary for Python

It's already the case that {"a": "b", "c": "d"} and {"c": "d", "a": "b"} compare as equal, but are distinguishable with respect to the order that iterators visit the items.

The history is that the iterator order used to be unpredictable, so the same object might give different orders when traversed multiple times and objects constructed by adding the items in different order might give the same order when traversed multiple times. However, a more recent implementation of dict started to traverse the items in the order the keys were first added, just because that was more convenient, and then the language changed to guarantee this. Of course, that meant that there was now something you could reliably determine about dicts that wasn't included in the equality rules that had always existed.


to post comments


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds