Re: Fast union/intersection of two sequences?

Aaron Watters (aaron@funcity.njit.edu)
Thu, 26 Jan 1995 12:57:46 GMT

In article <9501242219.AA24391@zippy.dvcorp.com> Donald Beaudry <don@dvcorp.com> writes:
>Guido wrote:
>> As a final warning, *if* a class defines a __hash__, it has the
>> responsibility to be immutable. [Otherwise all hell breaks loose...]

>This statement is a bit too strong for me. I think it is safe to say
>that your object can be mutable so long as the attributes used to
>compute the hash value (the keys) do not change....

I'd weaken it further to say that if you use something mutable as the
key in a dict it's your responsibility to make sure that its hash
value doesn't change until you delete it from the dict, just like
you shouldn't change a list you're iterating through inside a for
loop (all hell breaks loose if you do this too!). Let's not try to
make Python foolproof; fools are too clever (paraphrased from
somewhere). -a.
====
Sea anemones don't grow old, but we got all the laptops.
Seems like a fair trade now, but ask me again in 30 years. -a.