1

I want to add a list of tuples of edges to my GRaph, and some of the attributes are dictionary. The documentation seem to be able to accept dictionary but i am getting an error:

G = nx.MultiDiGraph()

edges = [(34, 1, {'id': '123a'}, {'date': '2017-11-27'}),
 (1, 27, {'id': '123a'}, {'date': '2017-11-27'})]

G.add_edges_from(edges)

My error:

TypeError: unhashable type: 'dict'

1 Answer 1

1

Try adding the edge attributes in a single dictionary:

G = nx.MultiDiGraph()

edges = [(34, 1, {'id': '123a', 'date': '2017-11-27'}),
 (1, 27, {'id': '123a', 'date': '2017-11-27'})]

G.add_edges_from(edges)
print(G[34][1][0]['id'])

ouput:

'123a'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.