NetworkX

Previous topic

networkx.DiGraph.neighbors_iter

Next topic

networkx.DiGraph.successors

networkx.DiGraph.__getitem__

DiGraph.__getitem__(n)

Return a dict of neighbors of node n. Use the expression ‘G[n]’.

Parameters:

n : node

A node in the graph.

Returns:

adj_dict : dictionary

The adjacency dictionary for nodes connected to n.

Notes

G[n] is similar to G.neighbors(n) but the internal data dictionary is returned instead of a list.

Assigning G[n] will corrupt the internal graph data structure. Use G[n] for reading data only.

Examples

>>> G = nx.Graph()   # or DiGraph, MultiGraph, MultiDiGraph, etc
>>> G.add_path([0,1,2,3])
>>> print G[0]
{1: {}}