Tuples -- who needs 'em
Hrvoje Niksic
hniksic at iskon.hr
Tue Apr 4 09:42:40 EDT 2000
Mike Fletcher <mfletch at tpresence.com> writes:
> I think the point that is being made is this:
> The _value_ of a mutable object cannot (easily) be used as a
> dictionary key...
> i.e. in this sequence, what is the value of the final line...
>
> s = [ 1,2,3 ]
> p = { s: 4, [2,3,4]: 5 }
> s[:] = [2,3,4]
> p[ [2,3,4] ]
The second line raises a TypeError, therefore the last line does not
have a meaningful value.
I only noted that Fredrik's sentence, as it was formulated, was wrong.
Mutable collections can be used as dictionary keys, as long as they
provide a meaningful hash function.
More information about the Python-list
mailing list