Warning

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

neighbors_iter

Graph.neighbors_iter(n)[source]

Return an iterator over all neighbors of node n.

Examples

>>> G = nx.Graph()   # or DiGraph, MultiGraph, MultiDiGraph, etc
>>> G.add_path([0,1,2,3])
>>> [n for n in G.neighbors_iter(0)]
[1]

Notes

It is faster to use the idiom “in G[0]”, e.g.

>>> G = nx.path_graph(4)
>>> [n for n in G[0]]
[1]