Moses Xu
Moses Xu

Reputation: 2160

Is the networkx.MultiDiGraph.edges method order-preserving?

MyNetwork is an instance of networkx.MultiDiGraph. I'm wondering if multiple runs of the following code is guaranteed to result exactly the same list containing all edges (along with edge attributes) in MyNetwork:

AllEdges = [(from_node,to_node,edge_key,edge_attributes) for (from_node,to_node,edge_key,edge_attributes) in MyNetwork.edges(keys=True,data=True)] 

Thank you for your kind answer.

Upvotes: 4

Views: 619

Answers (1)

Aric
Aric

Reputation: 25289

The list of edges returned from the MultiDiGraph.edges() method is not guaranteed to be in any order or the same when called repeatedly. You'll have to do more processing (e.g. a sort) or maintain a separate list or symbol table of edges if you need a particular ordering.

Upvotes: 4

Related Questions