Warning

This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.

edges_iter

DiGraph.edges_iter(nbunch=None, data=False, default=None)[source]

Return an iterator over the edges.

Edges are returned as tuples with optional data in the order (node, neighbor, data).

Parameters:
  • nbunch (iterable container, optional (default= all nodes)) – A container of nodes. The container will be iterated through once.
  • data (string 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).
  • default (value, optional (default=None)) – Value used for edges that dont have the requested attribute. Only relevant if data is not True or False.
Returns:

edge_iter – An iterator of (u,v) or (u,v,d) tuples of edges.

Return type:

iterator

See also

edges()
return a list of 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.DiGraph()   # or MultiDiGraph, etc
>>> G.add_path([0,1,2])
>>> G.add_edge(2,3,weight=5)
>>> [e for e in G.edges_iter()]
[(0, 1), (1, 2), (2, 3)]
>>> list(G.edges_iter(data=True)) # default data is {} (empty dict)
[(0, 1, {}), (1, 2, {}), (2, 3, {'weight': 5})]
>>> list(G.edges_iter(data='weight', default=1))
[(0, 1, 1), (1, 2, 1), (2, 3, 5)]
>>> list(G.edges_iter([0,2]))
[(0, 1), (2, 3)]
>>> list(G.edges_iter(0))
[(0, 1)]