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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With