NetworkX

Previous topic

networkx.algorithms.isolate.is_isolate

Next topic

Isomorphism

networkx.algorithms.isolate.isolates

networkx.algorithms.isolate.isolates(G)

Return list of isolates in the graph.

Isolates are nodes with no neighbors (degree zero).

Parameters :

G : graph

A networkx graph

Returns :

isolates : list

List of isolate nodes.

Examples

>>> G = nx.Graph()
>>> G.add_edge(1,2)
>>> G.add_node(3)
>>> nx.isolates(G)
[3]

To remove all isolates in the graph use >>> G.remove_nodes_from(nx.isolates(G)) >>> G.nodes() [1, 2]

For digraphs isolates have zero in-degree and zero out_degre >>> G = nx.DiGraph([(0,1),(1,2)]) >>> G.add_node(3) >>> nx.isolates(G) [3]