Warning

This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.

# weakly_connected_component_subgraphs¶

weakly_connected_component_subgraphs(G, copy=True)[source]

Generate weakly connected components as subgraphs.

Parameters: G (NetworkX graph) – A directed graph. copy (bool (default=True)) – If True make a copy of the graph attributes comp – A generator of graphs, one for each weakly connected component of G. generator

Examples

Generate a sorted list of weakly connected components, largest first.

>>> G = nx.path_graph(4, create_using=nx.DiGraph())
>>> [len(c) for c in sorted(nx.weakly_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.weakly_connected_component_subgraphs(G), key=len)


strongly_connected_components(), connected_components()