def find_or_create_node(branch, key):
 for node in branch:
  if (not isinstance(node, dict)):
   continue
  if (key in node):
   return node[key]
 new_branch = []
 node = {key: new_branch}
 branch.append(node)
 return new_branch

def find_or_create_node ( branch , key ) : for node in branch : if ( not isinstance ( node , dict ) ) : continue if ( key in node ) : return node [ key ] new_branch = [ ] node = { key : new_branch } branch . append ( node ) return new_branch
given a list .