On May 12, 12:25 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Fri, 11 May 2007 19:17:57 -0300, elventear <[EMAIL PROTECTED]> > escribió: > "The only required property is that objects which compare equal have the > same hash value; it is advised to somehow mix together (e.g., using > exclusive or) the hash values for the components of the object that also > play a part in comparison of objects. If a class does not define a > __cmp__() method it should not define a __hash__() operation either; if it > defines __cmp__() or __eq__() but not __hash__(), its instances will not > be usable as dictionary keys. If a class defines mutable objects and > implements a __cmp__() or __eq__() method, it should not implement > __hash__(), since the dictionary implementation requires that a key's hash > value is immutable (if the object's hash value changes, it will be in the > wrong hash bucket)."
Thanks for the information. I have a doubt regarding the wording in the paragraph on top. Since I am defining a hash for my object, it makes sense that I should be able to define equality. But I am not sure about inequality, in my specific case. The paragraph above mentions that __cmp__ should be defined if I define a __hash__, but in the default behaviour of __cmp__ inequality is included. So what should I do? Also why is equality necessary to be defined? Do dicts only use __hash__ or do they use equality as well? Thanks! -- http://mail.python.org/mailman/listinfo/python-list