networkx.classes.reportviews.EdgeView#

class EdgeView(G)[source]#

A EdgeView class for edges of a Graph

This densely packed View allows iteration over edges, data lookup like a dict and set operations on edges represented by node-tuples. In addition, edge data can be controlled by calling this object possibly creating an EdgeDataView. Typically edges are iterated over and reported as (u, v) node tuples or (u, v, key) node/key tuples for multigraphs. Those edge representations can also be using to lookup the data dict for any edge. Set operations also are available where those tuples are the elements of the set. Calling this object with optional arguments data, default and keys controls the form of the tuple (see EdgeDataView). Optional argument nbunch allows restriction to edges only involving certain nodes.

If data is False (the default) then iterate over 2-tuples (u, v). If data is True iterate over 3-tuples (u, v, datadict). Otherwise iterate over (u, v, datadict.get(data, default)). For Multigraphs, if keys is True, replace u, v with u, v, key above.

Parameters:
graphNetworkX graph-like class
nbunch(default= all nodes in graph) only report edges with these nodes
keys(only for MultiGraph. default=False) report edge key in tuple
databool or string (default=False) see above
defaultobject (default=None)

Examples

>>> G = nx.path_graph(4)
>>> EV = G.edges()
>>> (2, 3) in EV
True
>>> for u, v in EV:
...     print((u, v))
(0, 1)
(1, 2)
(2, 3)
>>> assert EV & {(1, 2), (3, 4)} == {(1, 2)}
>>> EVdata = G.edges(data="color", default="aqua")
>>> G.add_edge(2, 3, color="blue")
>>> assert (2, 3, "blue") in EVdata
>>> for u, v, c in EVdata:
...     print(f"({u}, {v}) has color: {c}")
(0, 1) has color: aqua
(1, 2) has color: aqua
(2, 3) has color: blue
>>> EVnbunch = G.edges(nbunch=2)
>>> assert (2, 3) in EVnbunch
>>> assert (0, 1) not in EVnbunch
>>> for u, v in EVnbunch:
...     assert u == 2 or v == 2
>>> MG = nx.path_graph(4, create_using=nx.MultiGraph)
>>> EVmulti = MG.edges(keys=True)
>>> (2, 3, 0) in EVmulti
True
>>> (2, 3) in EVmulti  # 2-tuples work even when keys is True
True
>>> key = MG.add_edge(2, 3)
>>> for u, v, k in EVmulti:
...     print((u, v, k))
(0, 1, 0)
(1, 2, 0)
(2, 3, 0)
(2, 3, 1)
__init__(G)#

Methods

data([data, default, nbunch])

Return a read-only view of edge data.

get(k[,d])

isdisjoint(other)

Return True if two sets have a null intersection.

items()

keys()

values()