## node, edge update
import networkx as nx
testG = nx.Graph()
testG.add_nodes_from([('A', {'weight':5}), ('B', {'weight':3})])
testG.add_edges_from([('A', 'B', {'weight':20})])
print(testG.nodes(data=True))
print(testG.edges(data=True))
print("="*20)
## update 나 추가하기
testG.nodes['A']['weight'] = 1000
testG.nodes['A']['gender'] = 'male'
print(testG.nodes(data=True))
testG.edges[('A', 'B')]['gender'] = 'aaa'
print(testG.edges(data=True))
print("="*20)
[('A', {'weight': 5}), ('B', {'weight': 3})]
[('A', 'B', {'weight': 20})]
====================
[('A', {'weight': 1000, 'gender': 'male'}), ('B', {'weight': 3})]
[('A', 'B', {'weight': 20, 'gender': 'aaa'})]
====================
댓글남기기