greg at cosc.canterbury.ac.nz
Mon Sep 6 04:00:58 CEST 2004
Alex Martelli wrote:
> Roy Smith <roy at panix.com> wrote:
> > 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.
> And your class's instances wouldn't then be hashable any more unless
> they defined a __hash__ method -- have you tried?
And even if you did give it a __hash__ method, you wouldn't
be able to get it to work properly as a dict key. It's an
inescapable fact of the way dicts work.
> > 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?
It wouldn't be a valid dictionary key. You might be able to fool
Python into accepting it, but it would malfunction.
More information about the Python-list