I have a class which is a subclass of tuple. I want to use instances of that class as elements of a set, but I get the error that it is an unhashable type. I guess this is because I’ve overridden the __eq__ and __ne__ methods. What should I do to restore my type’s hashability? I’m using Python 3.2.
I have a class which is a subclass of tuple . I want to
Share
you will need to majke your type hashable, which means implementing the
__hash__()member function in your class deriving from tuple.for example:
and this is what it looks like now:
note: you should absolutely read the documentation for the
__hash__()function, in order to understand the relationship between the comparison operators and the hash computation.