Why no list as dict key?
Chris Angelico
rosuav at gmail.com
Thu Apr 21 01:00:03 EDT 2022
On Thu, 21 Apr 2022 at 13:23, Abdur-Rahmaan Janhangeer
<arj.python at gmail.com> wrote:
>
> Assumes checking for object equality before inserting.
> If they are they same, do we need different hashes?
>
The point of the hash is to find things that are equal. That's why
1234, 1234.0, and 0j+1234.0 all have the same hash.
If equality changes, the hash does too. It's certainly possible to
have the hash come from object identity, but then so must equality. If
you want that, it's easy to do - just create your own object for the
state, rather than using a list. But then you have to use the original
object to look things up, instead of matching by the data.
Hashes are simply a short-hand for equality. That's all.
ChrisA
More information about the Python-list
mailing list