我想在GRaph中添加一个边缘元组列表,其中一些属性是字典。文档似乎能够接受字典但我收到错误:
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)
我的错误:
TypeError:不可用类型:' dict'
答案 0 :(得分:1)
尝试在单个字典中添加边缘属性:
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'])
输出中:
'123a'