Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I replaced this </p> <pre><code> self.to_min() == other.to_min() </code></pre> <p>with this </p> <pre><code> self.__hash__() == other.__hash__() </code></pre> <p>And also edited the <strong>eq</strong> to return boollean, rather than integer Now it works, I still wonders. Anyway, this is full code if anyone is interested:</p> <pre><code>class Time(object): ''' classdocs ''' def __init__(self, h, m): if isinstance(h, int) and isinstance(h, int): self.m = m self.h = h if(self.m &gt;= 60): self.h += self.m // 60 self.m %= 60 def __add__(self, m): return Time(self.h, self.m + m) def to_min(self): return self.h * 60 + self.m def __cmp__(self, other): print "__cmp__" if isinstance(other, Time): if self.to_min() &gt; other.to_min(): return 1 else: if self.__hash__() == other.__hash__(): return 0 else: return -1 def __eq__(self, other): print "__eq__" if isinstance(other, Time): if self.to_min() == other.to_min(): return True else: return False def __gt__(self, other): return self.to_min() &gt; other.to_min() def __ge__(self, other): return self.to_min() &gt;= other.to_min() def __lt__(self, other): return self.to_min() &lt; other.to_min() def __le__(self, other): return self.to_min() &lt;= other.to_min() def __str__ (self): return str(self.h) + ":" + str(self.m) def __hash__(self): print "__hash__" return self.to_min() # return 1 def __ne__(self, other): print "__ne__" return not self == other # a = set([Time(10,10), Time(10,20)]) # b = set([Time(10,10)]) # print a in set([b]) a = {Time(10,10)} print {Time(10,10)}.issubset(a) # print b.issubset( a) # for i in a: # print i in a </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload