I am implementing a graph manipulation script and I was puzzled with the following error:
Traceback (most recent call last):
File ".....py", line 12, in <module>
print(len(graph.predecessors(i)), len(graph.successors(i)))
>>TypeError: object of type 'dict_keyiterator' has no len()<<
This is the code:
import networkx as nx
graph = nx.DiGraph()
for i in range(10):
graph.add_node(i)
for i in range(9):
graph.add_edge(i, i+1)
for i in range(10):
print(len(graph.predecessors(i)), len(graph.successors(i)))
What is this dict_keyiterator
and how to fix my code? Thanks!