get_edge_data

Graph.get_edge_data(u, v, 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.
Returns:

edge_dict – The edge attribute dictionary.

Return type:

dictionary

Notes

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

>>> G = nx.path_graph(4)  # or DiGraph, MultiGraph, MultiDiGraph, etc
>>> G[0][1]
{}

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

>>> G[0][1]['weight'] = 7
>>> G[0][1]['weight']
7
>>> G[1][0]['weight']
7

Examples

>>> G = nx.path_graph(4)  # or DiGraph, MultiGraph, MultiDiGraph, etc
>>> G.get_edge_data(0, 1)  # default edge data is {}
{}
>>> e = (0,1)
>>> G.get_edge_data(*e)  # tuple form
{}
>>> G.get_edge_data('a','b',default=0)  # edge not in graph, return 0
0