strongly_connected_component_subgraphs¶
-
strongly_connected_component_subgraphs
(G, copy=True)[source]¶ Generate strongly connected components as subgraphs.
Parameters: - G (NetworkX Graph) – A directed graph.
- copy (boolean, optional) – if copy is True, Graph, node, and edge attributes are copied to the subgraphs.
Returns: comp – A generator of graphs, one for each strongly connected component of G.
Return type: generator of graphs
Examples
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)
See also
connected_component_subgraphs()
,weakly_connected_component_subgraphs()