objects as mutable dictionary keys

Andrew Koenig ark at acm.org
Mon Dec 27 18:32:47 EST 2004


"Peter Maas" <peter at somewhere.com> wrote in message 
news:33bi4tF3u4cilU1 at individual.net...

> This leads to the question:
>
> Why does (t1 == t2 => d[t1] identical to d[t2]) hold for user defined
> objects and not for lists? My answer: because the cmp function looks at
> id() for user defined objects and at list content for lists.

Yes.

> Why does the cmp function _have_ to look at lists contents?
> My answer: because of the existence of list literals.

No.  The reason is that lists are containers, and it it is reasonable to 
define container equality recursively as element equality.  There are no set 
literals, but that doesn't mean that set equality should be identity.





More information about the Python-list mailing list