MCPcopy Create free account
hub / github.com/easy-graph/Easy-Graph / isolates

Function isolates

easygraph/functions/isolate.py:40–82  ·  view source on GitHub ↗

Iterator over isolates in the graph. An *isolate* is a node with no neighbors (that is, with degree zero). For directed graphs, this means no in-neighbors and no out-neighbors. Parameters ---------- G : EasyGraph graph Returns ------- iterator An iterat

(G)

Source from the content-addressed store, hash-verified

38
39
40def isolates(G):
41 """Iterator over isolates in the graph.
42
43 An *isolate* is a node with no neighbors (that is, with degree
44 zero). For directed graphs, this means no in-neighbors and no
45 out-neighbors.
46
47 Parameters
48 ----------
49 G : EasyGraph graph
50
51 Returns
52 -------
53 iterator
54 An iterator over the isolates of `G`.
55
56 Examples
57 --------
58 To get a list of all isolates of a graph, use the :class:`list`
59 constructor::
60
61 >>> G = eg.Graph()
62 >>> G.add_edge(1, 2)
63 >>> G.add_node(3)
64 >>> list(eg.isolates(G))
65 [3]
66
67 To remove all isolates in the graph, first create a list of the
68 isolates, then use :meth:`Graph.remove_nodes_from`::
69
70 >>> G.remove_nodes_from(list(eg.isolates(G)))
71 >>> list(G)
72 [1, 2]
73
74 For digraphs, isolates have zero in-degree and zero out_degre::
75
76 >>> G = eg.DiGraph([(0, 1), (1, 2)])
77 >>> G.add_node(3)
78 >>> list(eg.isolates(G))
79 [3]
80
81 """
82 return (n for n, d in G.degree().items() if d == 0)
83
84
85def number_of_isolates(G):

Callers 1

number_of_isolatesFunction · 0.85

Calls 1

degreeMethod · 0.45

Tested by

no test coverage detected