Tuple question

Roy Smith roy at panix.com
Sun Sep 5 10:35:43 EDT 2004


I asked:
> How is a class instance's mutability any less of disqualifier for
> key-ness than a list's mutability?

Benjamin Niemann <pink at odahoda.de> wrote:

> a = [1, 2, 3]
> b = [1, 2, 3]
> if a == b:
> 	print "List equality is based on content"

Tuple (and string) equality is based on content too.  So what?  I can 
give my data class an __eq__ method, and then my class instance equality 
would also based on content.

So, to restate my original question, why should my mutable, 
content-based-eqality class instance be a valid dictionary key, when a 
list is not?  Which part of a list's behavior makes it inherently 
unusable as a key?  I'm not asking about design philosophy, I'm asking 
about observable behavior.



More information about the Python-list mailing list