objects as mutable dictionary keys
ark at acm.org
Tue Dec 28 00:32:47 CET 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.
> 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