def to_dict_of_dicts(G, nodelist=None, edge_data=None):
 dod = {}
 if (nodelist is None):
  if (edge_data is None):
   for (u, nbrdict) in G.adjacency():
    dod[u] = nbrdict.copy()
  else:
   for (u, nbrdict) in G.adjacency():
    dod[u] = dod.fromkeys(nbrdict, edge_data)
 elif (edge_data is None):
  for u in nodelist:
   dod[u] = {}
   for (v, data) in ((v, data) for (v, data) in G[u].items() if (v in nodelist)):
    dod[u][v] = data
 else:
  for u in nodelist:
   dod[u] = {}
   for v in (v for v in G[u] if (v in nodelist)):
    dod[u][v] = edge_data
 return dod

def to_dict_of_dicts ( G , nodelist = None , edge_data = None ) : dod = { } if ( nodelist is None ) : if ( edge_data is None ) : for ( u , nbrdict ) in G . adjacency ( ) : dod [ u ] = nbrdict . copy ( ) else : for ( u , nbrdict ) in G . adjacency ( ) : dod [ u ] = dod . fromkeys ( nbrdict , edge_data ) elif ( edge_data is None ) : for u in nodelist : dod [ u ] = { } for ( v , data ) in ( ( v , data ) for ( v , data ) in G [ u ] . items ( ) if ( v in nodelist ) ) : dod [ u ] [ v ] = data else : for u in nodelist : dod [ u ] = { } for v in ( v for v in G [ u ] if ( v in nodelist ) ) : dod [ u ] [ v ] = edge_data return dod
return adjacency representation of graph as a dictionary of dictionaries .