[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-list
Subject:    Re: objects as mutable dictionary keys
From:       "Andrew Koenig" <ark () acm ! org>
Date:       2004-12-27 22:04:18
Message-ID: CF%zd.1174390$Gx4.223405 () bgtnsc04-news ! ops ! worldnet ! att ! net
[Download RAW message or body]

"Peter Maas" <peter@somewhere.com> wrote in message 
news:33bdosF3qm2j6U1@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?


-- 
http://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic