MultiDiGraph.out_edges#

property MultiDiGraph.out_edges#

An OutMultiEdgeView of the Graph as G.edges or G.edges().

edges(self, nbunch=None, data=False, keys=False, default=None)

The OutMultiEdgeView provides set-like operations on the edge-tuples as well as edge attribute lookup. When called, it also provides an EdgeDataView object which allows control of access to edge attributes (but does not provide set-like operations). Hence, G.edges[u, v, k]['color'] provides the value of the color attribute for the edge from u to v with key k while for (u, v, k, c) in G.edges(data='color', default='red', keys=True): iterates through all the edges yielding the color attribute with default 'red' if no color attribute exists.

Edges are returned as tuples with optional data and keys in the order (node, neighbor, key, data). If keys=True is not provided, the tuples will just be (node, neighbor, data), but multiple tuples with the same node and neighbor will be generated when multiple edges between two nodes exist.

Parameters:
nbunchsingle node, container, or all nodes (default= all nodes)

The view will only report edges from these nodes.

datastring or bool, optional (default=False)

The edge attribute returned in 3-tuple (u, v, ddict[data]). If True, return edge attribute dict in 3-tuple (u, v, ddict). If False, return 2-tuple (u, v).

keysbool, optional (default=False)

If True, return edge keys with each edge, creating (u, v, k, d) tuples when data is also requested (the default) and (u, v, k) tuples when data is not requested.

defaultvalue, optional (default=None)

Value used for edges that don’t have the requested attribute. Only relevant if data is not True or False.

Returns:
edgesOutMultiEdgeView

A view of edge attributes, usually it iterates over (u, v) (u, v, k) or (u, v, k, d) tuples of edges, but can also be used for attribute lookup as edges[u, v, k]['foo'].

See also

in_edges, out_edges

Notes

Nodes in nbunch that are not in the graph will be (quietly) ignored. For directed graphs this returns the out-edges.

Examples

>>> G = nx.MultiDiGraph()
>>> nx.add_path(G, [0, 1, 2])
>>> key = G.add_edge(2, 3, weight=5)
>>> key2 = G.add_edge(1, 2) # second edge between these nodes
>>> [e for e in G.edges()]
[(0, 1), (1, 2), (1, 2), (2, 3)]
>>> list(G.edges(data=True))  # default data is {} (empty dict)
[(0, 1, {}), (1, 2, {}), (1, 2, {}), (2, 3, {'weight': 5})]
>>> list(G.edges(data="weight", default=1))
[(0, 1, 1), (1, 2, 1), (1, 2, 1), (2, 3, 5)]
>>> list(G.edges(keys=True))  # default keys are integers
[(0, 1, 0), (1, 2, 0), (1, 2, 1), (2, 3, 0)]
>>> list(G.edges(data=True, keys=True))
[(0, 1, 0, {}), (1, 2, 0, {}), (1, 2, 1, {}), (2, 3, 0, {'weight': 5})]
>>> list(G.edges(data="weight", default=1, keys=True))
[(0, 1, 0, 1), (1, 2, 0, 1), (1, 2, 1, 1), (2, 3, 0, 5)]
>>> list(G.edges([0, 2]))
[(0, 1), (2, 3)]
>>> list(G.edges(0))
[(0, 1)]
>>> list(G.edges(1))
[(1, 2), (1, 2)]