def get_dict(self, u=None):
        """ A recursive function to return the content of the tree in a dict."""
        if u is None:
            return self.get_dict(self.root)
        children = []
        for v in self.adj_list[u]:
            children.append(self.get_dict(v))
        ret = {"name": u, "children": children}
        return ret
def get_dict ( self , u = None ) : if u is None : return self . get_dict ( self . root ) children = [ ] for v in self . adj_list [ u ] : children . append ( self . get_dict ( v ) ) ret = { "name" : u , "children" : children } return ret
A recursive function to return the content of the tree in a dict.