MultiGraph.adj#

property MultiGraph.adj#

Graph adjacency object holding the neighbors of each node.

This object is a read-only dict-like structure with node keys and neighbor-dict values. The neighbor-dict is keyed by neighbor to the edgekey-data-dict. So G.adj[3][2][0]['color'] = 'blue' sets the color of the edge (3, 2, 0) to "blue".

Iterating over G.adj behaves like a dict. Useful idioms include for nbr, edgesdict in G.adj[n].items():.

The neighbor information is also provided by subscripting the graph.

Examples

>>> e = [(1, 2), (1, 2), (1, 3), (3, 4)]  # list of edges
>>> G = nx.MultiGraph(e)
>>> G.edges[1, 2, 0]["weight"] = 3
>>> result = set()
>>> for edgekey, data in G[1][2].items():
...     result.add(data.get('weight', 1))
>>> result
{1, 3}

For directed graphs, G.adj holds outgoing (successor) info.