Late-binding of function defaults (was Re: What is a function parameter =[] for?)

Mark Lawrence breamoreboy at yahoo.co.uk
Thu Nov 26 06:17:56 EST 2015


On 26/11/2015 06:52, Marko Rauhamaa wrote:
> Steven D'Aprano <steve at 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




More information about the Python-list mailing list