def replace_scc(G): components = strongly_connected_components(G) c = {} # figure out which for i in xrange(len(components)): # component each node for node in components[i]: # belongs to c[node] = i + 1 H = networkx.DiGraph() # create a new graph for u,v in G.edges_iter(): # replace endpoints with H.add_edge(c[u], c[v]) # new component numbers return H