Warning
This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.
neighbors¶
- Graph.neighbors(n)¶
Return a list of the nodes connected to the node n.
Parameters : n : node
A node in the graph
Returns : nlist : list
A list of nodes that are adjacent to n.
Raises : NetworkXError
If the node n is not in the graph.
Notes
It is usually more convenient (and faster) to access the adjacency dictionary as G[n]:
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_edge('a','b',weight=7) >>> G['a'] {'b': {'weight': 7}}
Examples
>>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_path([0,1,2,3]) >>> G.neighbors(0) [1]