Orri Ganel wrote:
Thanks to Jeff and John Fouhy . . . However, my question now is: can I
treat Nodes sometimes the same and sometimes not? I want to treat
Nodes whose cargo is the same the same everywhere *except* in a
dictionary, because I want the user to be able to use LinkedList in a
broader way than sets allow . . . In order to do this, I need my
__hash__() method to treat Nodes differently than the rich comparison
methods do.  Is this a Bad Idea(tm) ?

The problem is, if you have two Nodes a and b where a == b, you will expect that for any dictionary d[a] == d[b]. If Node.__eq__() has different semantics than Node.__hash__() this expectation will not be correct.


Kent

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to