Skip to content Skip to sidebar Skip to footer

How To Retrieve Or Iterate Over Edge Keys In Python Networkx Multidigraph

I have a MultiDiGraph, in which there may exist multiple edges between nodes that are differentiated based on a key. Across the graph I have many keys and I'd like to iterate over

Solution 1:

NetworkX stores the keys in the adjacency structure so the only way to access them is by iterating over data

This seems like the best way

# Iterate over edges in the map and store the keyskeys = set(e[2] for e in G.edges_iter(keys=True))

unless you can the keys as you add the edges. You could subclass the add_edge method to store the keys in an separate data structure as you add them.

Post a Comment for "How To Retrieve Or Iterate Over Edge Keys In Python Networkx Multidigraph"