def to_dict_of_lists(G, nodelist=None):
 if (nodelist is None):
  nodelist = G
 d = {}
 for n in nodelist:
  d[n] = [nbr for nbr in G.neighbors(n) if (nbr in nodelist)]
 return d

def to_dict_of_lists ( G , nodelist = None ) : if ( nodelist is None ) : nodelist = G d = { } for n in nodelist : d [ n ] = [ nbr for nbr in G . neighbors ( n ) if ( nbr in nodelist ) ] return d
return adjacency representation of graph as a dictionary of lists .