Tuples -- who needs 'em

Mike Fletcher mfletch at tpresence.com
Tue Apr 4 09:43:14 EDT 2000


Certainly it raises a TypeError, currently the implementation prevents you
from making the mistake of using a mutable sequence as a dictionary key. If
you prefer, the question is:
	in this sequence, what should be the value of the final line, if we
allow mutable sequences as dictionary keys.

The question of what a "meaningful" hash function would be for a mutable
sequence is the crux of the issue, and the thrust of my attempted
clarification.  Without a fixed value, the "meaning" of a hash function for
a mutable sequence is currently undefined.  Define what that meaning should
be (and do so convincingly), and the implementers might be able to implement
it :) .

Of course, since you were just playing with the words, I'll let the matter
rest (matters are often tired out by all this word-play, crotchety old
things, should never let them out of the rest home...) :) 
*poof*

-----Original Message-----
From: Hrvoje Niksic [mailto:hniksic at iskon.hr]
Sent: Tuesday, April 04, 2000 9:43 AM
To: Mike Fletcher
Cc: python-list at python.org
Subject: Re: Tuples -- who needs 'em


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.

-- 
http://www.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list