Warning

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

get_edge_data

MultiGraph.get_edge_data(u, v, key=None, default=None)[source]

Return the attribute dictionary associated with edge (u,v).

Parameters:
  • u,v (nodes) –
  • default (any Python object (default=None)) – Value to return if the edge (u,v) is not found.
  • key (hashable identifier, optional (default=None)) – Return data only for the edge with specified key.
Returns:

edge_dict – The edge attribute dictionary.

Return type:

dictionary

Notes

It is faster to use G[u][v][key].

>>> G = nx.MultiGraph() # or MultiDiGraph
>>> G.add_edge(0,1,key='a',weight=7)
>>> G[0][1]['a']  # key='a'
{'weight': 7}

Warning: Assigning G[u][v][key] corrupts the graph data structure. But it is safe to assign attributes to that dictionary,

>>> G[0][1]['a']['weight'] = 10
>>> G[0][1]['a']['weight']
10
>>> G[1][0]['a']['weight']
10

Examples

>>> G = nx.MultiGraph() # or MultiDiGraph
>>> G.add_path([0,1,2,3])
>>> G.get_edge_data(0,1)
{0: {}}
>>> e = (0,1)
>>> G.get_edge_data(*e) # tuple form
{0: {}}
>>> G.get_edge_data('a','b',default=0) # edge not in graph, return 0
0