MCPcopy
hub / github.com/networkx/networkx / NodeView

Class NodeView

networkx/classes/reportviews.py:118–284  ·  view source on GitHub ↗

A NodeView class to act as G.nodes for a NetworkX Graph Set operations act on the nodes without considering data. Iteration is over nodes. Node data can be looked up like a dict. Use NodeDataView to iterate over node data or to specify a data attribute for lookup. NodeDataView is cr

Source from the content-addressed store, hash-verified

116
117# NodeViews
118class NodeView(Mapping, Set):
119 """A NodeView class to act as G.nodes for a NetworkX Graph
120
121 Set operations act on the nodes without considering data.
122 Iteration is over nodes. Node data can be looked up like a dict.
123 Use NodeDataView to iterate over node data or to specify a data
124 attribute for lookup. NodeDataView is created by calling the NodeView.
125
126 Parameters
127 ----------
128 graph : NetworkX graph-like class
129
130 Examples
131 --------
132 >>> G = nx.path_graph(3)
133 >>> NV = G.nodes()
134 >>> 2 in NV
135 True
136 >>> for n in NV:
137 ... print(n)
138 0
139 1
140 2
141 >>> assert NV & {1, 2, 3} == {1, 2}
142
143 >>> G.add_node(2, color="blue")
144 >>> NV[2]
145 {'color': 'blue'}
146 >>> G.add_node(8, color="red")
147 >>> NDV = G.nodes(data=True)
148 >>> (2, NV[2]) in NDV
149 True
150 >>> for n, dd in NDV:
151 ... print((n, dd.get("color", "aqua")))
152 (0, 'aqua')
153 (1, 'aqua')
154 (2, 'blue')
155 (8, 'red')
156 >>> NDV[2] == NV[2]
157 True
158
159 >>> NVdata = G.nodes(data="color", default="aqua")
160 >>> (2, NVdata[2]) in NVdata
161 True
162 >>> for n, dd in NVdata:
163 ... print((n, dd))
164 (0, 'aqua')
165 (1, 'aqua')
166 (2, 'blue')
167 (8, 'red')
168 >>> NVdata[2] == NV[2] # NVdata gets 'color', NV gets datadict
169 False
170 """
171
172 __slots__ = ("_nodes",)
173
174 def __getstate__(self):
175 return {"_nodes": self._nodes}

Callers 1

nodesMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…