【发布时间】:2015-01-28 03:25:43
【问题描述】:
nodes_g = {}
with open("calls.txt") as fp3:
for line in fp3:
rows3 = line.split(";")
x, node1, node2, sec, y = line.split(";")
if node1 not in nodes_g:
nodes_g[node1, node2] = int(rows3[3])
elif node1 in nodes_g and node2 in nodes_g:
nodes_g[node1, node2] += int(rows3[3])
print(nodes_g)
我现在有这个,其中 node1 是呼叫号码,node2 是接收号码,sec 或 rows3[3] 是两个号码之间通话的秒数。我想使用文件的第三行更新 dict 的值(通话秒数),但是不是更新它,而是用下一行 3 值替换它,依此类推。
calls.txt 文件的链接:http://pastebin.com/RSMnXDtq
【问题讨论】:
标签: python python-3.x dictionary tuples