Generate strongly connected components as subgraphs.
- G (NetworkX Graph) – A directed graph.
- copy (boolean, optional) – if copy is True, Graph, node, and edge attributes are copied to the subgraphs.
comp – A generator of graphs, one for each strongly connected component of G.
generator of graphs
Generate a sorted list of strongly connected components, largest first.
>>> G = nx.cycle_graph(4, create_using=nx.DiGraph()) >>> G.add_cycle([10, 11, 12]) >>> [len(Gc) for Gc in sorted(nx.strongly_connected_component_subgraphs(G), ... key=len, reverse=True)] [4, 3]
If you only want the largest component, it’s more efficient to use max instead of sort.
>>> Gc = max(nx.strongly_connected_component_subgraphs(G), key=len)