networkx.classes.reportviews.NodeView#

class NodeView(graph)[source]#

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 created by calling the NodeView.

Parameters:
graphNetworkX graph-like class

Examples

>>> G = nx.path_graph(3)
>>> NV = G.nodes()
>>> 2 in NV
True
>>> for n in NV:
...     print(n)
0
1
2
>>> assert NV & {1, 2, 3} == {1, 2}
>>> G.add_node(2, color="blue")
>>> NV[2]
{'color': 'blue'}
>>> G.add_node(8, color="red")
>>> NDV = G.nodes(data=True)
>>> (2, NV[2]) in NDV
True
>>> for n, dd in NDV:
...     print((n, dd.get("color", "aqua")))
(0, 'aqua')
(1, 'aqua')
(2, 'blue')
(8, 'red')
>>> NDV[2] == NV[2]
True
>>> NVdata = G.nodes(data="color", default="aqua")
>>> (2, NVdata[2]) in NVdata
True
>>> for n, dd in NVdata:
...     print((n, dd))
(0, 'aqua')
(1, 'aqua')
(2, 'blue')
(8, 'red')
>>> NVdata[2] == NV[2]  # NVdata gets 'color', NV gets datadict
False
__init__(graph)[source]#

Methods

data([data, default])

Return a read-only view of node data.

get(k[,d])

isdisjoint(other)

Return True if two sets have a null intersection.

items()

keys()

values()