1 回答

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超6個(gè)贊
試試這個(gè) :
def add_edge(graph, aa1, aa2):
first_value = graph[aa1].copy()
for k,v in first_value.items():
if aa2 in k:
graph[aa1].update({aa2:v+1})
break
else:
graph[aa1].update({aa2:1})
second_value = graph[aa2].copy()
for k,v in second_value.items():
if aa1 in k:
graph[aa2].update({aa1:v+1})
break
else:
graph[aa2].update({aa1:1})
return graph
- 1 回答
- 0 關(guān)注
- 137 瀏覽
添加回答
舉報(bào)