The following problem is using Python 3.9 and Networkx 2.5
I need to output a subgraph of G that only contains edges between nodes in a list and directly neighboring nodes with edge weights less than 100. Currently I am using the following code, but only am able to pull the edge weight. I need to get both the node name and edge weight.
list_neighbors=G.neighbors('Rochester, NY')
for i in list_neighbors:
if G.edges[('Rochester, NY',i)]['weight']<100:
print (G.edges[('Rochester, NY',i)])
OUTPUT: {'weight': 88}
How do I get the output to include the Node Names as well (input node and it's neighbor that meets criteria of weight)
i
should contain the name of the neighbour. – Sparky05print(i, G.edges[('Rochester, NY',i)])
. – Paul Brodersen