On 26/11/2015 06:52, Marko Rauhamaa wrote:
Steven D'Aprano <st...@pearwood.info>:

Making tuples mutable would break their use as dictionary keys, which is a
*critical* use.

No, it wouldn't. Any object that provides __hash__() and __eq__() can be
used as a key.


Almost, see https://wiki.python.org/moin/DictionaryKeys. Under the title "Types Usable as Dictionary Keys" it states "The discussion above should explain why Python requires that:

To be used as a dictionary key, an object must support the hash function (e.g. through __hash__), equality comparison (e.g. through __eq__ or __cmp__), and must satisfy the correctness condition above."

The correctness condition is:-

"For such a lookup algorithm to work correctly, the hash functions provided must guarantee that if two keys produce different hash values then the two key objects are not equivalent, that is,

for all i1, i2, if hash(i1) != hash(i2), then i1 != i2"

Aren't search engines just wonderful :)

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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

Reply via email to