from json import dumps class Tree(object): def __init__(self, label, children=[]): self.label = label self.children = children def __dict__(self): return {self.label: [c.__dict__() for c in sorted(self.children)]} def __str__(self, indent=None): return dumps(self.__dict__(), indent=indent) def __lt__(self, other): return self.label < other.label def __eq__(self, other): return self.__dict__() == other.__dict__() def from_pov(self, from_node): pass def path_to(self, from_node, to_node): pass