Am 05.02.20 um 20:55 schrieb klau...@gmail.com:

If not, why should a class not define __hash__, if it does not define __eq__?

Hashes are not unique. When you insert or look up something in a hashtable, the hash is computed and used as the index into the table. Because the hash is not necessarily unique, if hash(a)=hash(b), it can still be that a=/= b. Therefore, in a second step, a is compared to b if the hashes match.

Therefore, you need a comparison operator which is compatible with the hash function, i.e. if a==b, then hash(a) must be equal to hash(b).

Christian

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to