python - networkx best practice getting edge attribute value while iterating over edges -
given list of edges (or generator). readable way identify edges attribute value? example edges 'edge_type' of 'foo'?
currently, code looks this:
for edge in nx_graph.out_edges(my_node): edge_type = nx_graph[edge[0]][edge[1]]['edge_type'] if edge_type == 'foo': ...
due many brackets not easy read...
a more readable approach:
for edge in g.edges_iter(data=true): if edge[2]['edge_type']=='foo': ...
yet still not clear (especially [2]
). also, not sure how use out_edges()
here's option
for edge in {(u,v,data) u,v,data in g.edges_iter(data=true) if data['edge_type']=='foo'}: ...
Comments
Post a Comment