Why are tuples immutable?
aleaxit at yahoo.com
Wed Dec 22 20:34:33 CET 2004
Jeff Shannon <jeff at ccvcorp.com> wrote:
> hashes) is that, for a well-behaved hash function, then A == B should
> imply that hash(A) == hash(B). (The reverse is *not* true, however --
> hash(A) == hash(B) does not necessarily say anything about whether A == B.)
> If that is a correct condition for a well-behaved hash function, then it
Yep, I consider it part of the axioms of hash.
> is indeed impossible to have a well-behaved hash function that can be
> useful in the face of object mutation. For something like a list, one
> can only define a poorly-behaved hash-like function.
In terms of performance, yes. In terms of satisfying the axioms, no;
just "def __hash__(self): return 23" (or any other int) and the axioms
will be satisfied. (Every isntance will hash to the same bucket, so,
performance sucks -- but, formally, everything IS fine;-).
More information about the Python-list