def areCousins(n1, n2, F): if(n1 == n2): return False p1 = T.parent(n1, F) p2 = T.parent(n2, F) if(p1 == None or p2 == None): return False else: return (areSiblings(p1, p2, F) or areCousins(p1, p2, F))
def areSiblings(n1, n2, F): return (n1 != n2) and (T.parent(n1, F) == T.parent(n2, F))