def parse_neighbors_graph(neighbors, vars=[]):
 graph = defaultdict(list)
 for var in vars:
  graph[var] = []
 specs = [spec.split(':') for spec in neighbors.split(';')]
 for (v, v_neighbors) in specs:
  v = v.strip()
  graph.setdefault(v, [])
  for u in v_neighbors.split():
   graph[v].append(u)
   graph[u].append(v)
 return graph

def parse_neighbors_graph ( neighbors , vars = [ ] ) : graph = defaultdict ( list ) for var in vars : graph [ var ] = [ ] specs = [ spec . split ( ':' ) for spec in neighbors . split ( ';' ) ] for ( v , v_neighbors ) in specs : v = v . strip ( ) graph . setdefault ( v , [ ] ) for u in v_neighbors . split ( ) : graph [ v ] . append ( u ) graph [ u ] . append ( v ) return graph
a utility for converting a string of the form x: y z; y: z into a dict mapping variables to their neighbors .