When constructing a graph from an edge list with integer node IDs, iterating over n.nodes and accessing dictionary-based methods such as degrees() results in a KeyError.
This is not working:
n = pp.Graph.from_edge_list([(0, 1), (1, 2), (2, 1)])
for v in n.nodes:
print(n.degrees()[v])
Error:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
Cell In[25], line 3
1 n = pp.Graph.from_edge_list([(0, 1), (1, 2), (2, 1)])
2 for v in n.nodes:
----> 3 print(n.degrees()[v])
KeyError: 0
Working example with string node IDs
n = pp.Graph.from_edge_list([('A', 'B'), ('B', 'C'), ('C', 'A')])
for v in n.nodes:
print(n.degrees()[v])
When constructing a graph from an edge list with integer node IDs, iterating over
n.nodesand accessing dictionary-based methods such asdegrees()results in aKeyError.This is not working:
Error:
Working example with string node IDs