On Mon, Dec 21, 2020 at 5:27 PM Christopher Barker <pythonchb@gmail.com> wrote:
Surely what you're looking for is some kind of typed hash table?
Maybe, maybe not. My impression is that the Typed hash table is a kluge to get around this one issue. As others have pointed out, 1 and 1.0 are considered equal, and thus hash the same — a typed hash table would not consider them the same. And while maybe useful, it would violate the spirit of duck typing. If you really want that kind of static typing, maybe Python is not the language for the job.
I've occasionally wanted an "identity set". Except, after I want it, I pretty quickly always realize I don't actually want it. Exactly what strings and integers will actually be interned, etc? There's a lot of implementation dependent stuff there that isn't a clear semantics (I mean, it's knowable, but too complex). In any case, I know how to write that in a few lines if I feel like having it. Basically just use pairs `(id(x), x)` in a set. That's more specific than `(type(x), x)`, although both have their own gotchas. -- The dead increasingly dominate and strangle both the living and the not-yet born. Vampiric capital and undead corporate persons abuse the lives and control the thoughts of homo faber. Ideas, once born, become abortifacients against new conceptions.