objects as mutable dictionary keys
Andrew Koenig
ark at acm.org
Mon Dec 27 17:04:18 EST 2004
"Peter Maas" <peter at somewhere.com> wrote in message
news:33bdosF3qm2j6U1 at individual.net...
> This strikes me because if one can do this with instances of user
> defined classes why not with lists? Trying to use lists as dict
> keys yields "TypeError: list objects are unhashable". So why are
> list objects unhashable and user defined objects hashable? For
> user defined objects hash(x1) = id(x1), why not do the same
> with lists?
If d is a dict and t1 and t2 are tuples, and t1 == t2, then d[t1] and d[t2]
are the same element.
If lists used the id as the hash, this property would not hold for lists.
Can you give me an example of a program for which you consider such behavior
to be useful?
More information about the Python-list
mailing list