I'm representing trees with tuples. Say
t1=(t2,t3) and t4=(t5,t6)
Is it true that when comparing two such trees with ==
, it first tests if references t2
and t5
are equal then if references t3
and t6
are equal, if they are not equal then it tries to compare the actual contents of t2
and t5
, then the contents of t3
and t6
?
LE:
The following code doesn't call __eq__
it seems that my assumption is right, and that it doesn't evaluate the tuples recursively as I understand from the documentation.
class C:
def __init__(self,a):
self.a=a
def __eq__(self,oth):
print self.a,oth.a
return oth.a==self.a
p=(C(1),C(2))
l=(p,p)
f=(p,p)
print l==f
On the other hand this code does call __eq__
q=(C(1),C(2))
p=(C(1),C(2))
l=(q,q)
f=(p,p)
print l==f