Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NetworkX OutEdgeView to list

I need to covert networkx edges' OutEdgeView data to a list.

I remember the graph.edges(data=True) used to return a list like [u,v,{data}]. But now the networks returns something OutEdgeView([u,v,{data}]). How could I get the original kind of list?

Thanks

like image 311
Kevin Avatar asked Oct 23 '25 19:10

Kevin


1 Answers

Networkx recently moved to version 2.0 from 1.11. You should read the migration guide.

In this case the guide provides an example:

>>> D = nx.DiGraph()
>>> D.add_edges_from([(1, 2), (2, 3), (1, 3), (2, 4)])
>>> D.nodes
NodeView((1, 2, 3, 4))
>>> list(D.nodes)
[1, 2, 3, 4]
>>> D.edges
OutEdgeView([(1, 2), (1, 3), (2, 3), (2, 4)])
>>> list(D.edges)
[(1, 2), (1, 3), (2, 3), (2, 4)]

In general if you need to convert X to a list, you use list(X).

This works for your case where you've used data=True as well.

like image 164
Joel Avatar answered Oct 26 '25 07:10

Joel