3.3.3.8. 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 an iterator.
Assigning G[n] will corrupt the internal graph data structure. Use G[n] for reading data only.
Examples
>>> G = nx.path_graph(4) # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G[0] {1: {}}