code: def flatten(self, d=None):
          
          if d is None:
              d = {}
          if self.name is not None:
              d[self.name] = self
          for child in self.children:
              child.flatten(d=d)
          return d
docs: Flatten tree structure to a one level dictionary.
  
  
          Args:
              d (dict, optional): output dictionary to update
  
          Returns:
              dict: Node.name -> Node. The returned dictionary includes the
                    current Node and all its children.