NetworkX

Previous topic

networkx.Graph.edges

Next topic

networkx.Graph.get_edge_data

networkx.Graph.edges_iter

Graph.edges_iter(nbunch=None, data=False)

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 : bool, optional (default=False)

If True, return edge attribute dict in 3-tuple (u,v,data).

Returns:

edge_iter : iterator

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

See also

edges
return a list of edges

Notes

Nodes in nbunch that are not in the graph will be (quietly) ignored.

Examples

>>> G = nx.Graph()   # or MultiGraph, etc
>>> G.add_path([0,1,2,3])
>>> [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, {})]
>>> list(G.edges_iter([0,3]))
[(0, 1), (3, 2)]
>>> list(G.edges_iter(0))
[(0, 1)]