Reputation: 2461
I am following this tutorial: graph tutorial on my own data file. but I am getting stuck on the last bit. the code seems to throw:
(most recent call last)<ipython-input-193-7227d35394c0> in <module>()
1 for node in links: #loops through each link and changes each dictionary to a tuple so networkx can read in the information
2 edges = node.items()
----> 3 G.add_edge(*edges[0]) #takes the tuple from the list and unpacks the tuples
4
5 nx.draw(G)
TypeError: 'dict_items' object does not support indexing
is there a fix? I'm sort of stuck.
Upvotes: 1
Views: 606
Reputation: 140188
This is probably python-2 only compatible code.
In python 2, dict.items()
returns a list of tuples (key, value) as opposed to dict.iteritems()
In python 3, dict.iteritems()
has been removed, and dict.items()
returns an iterator.
So you have to explicitly convert it to list
to get access to the elements by index:
edges = list(node.items())
Upvotes: 1