from collections import defaultdict
with open('file') as f: # open file in read only mode
my_dict = defaultdict(float) # will hold default value as 0.0 for any key
for line in f.readlines(): # iterate over each line
_, key, val, _ = line.split(';') # split line on ';' and take 1 & 2 index
my_dict[key] += val # add amount to service
您可以在此处使用^{} :
相关问题 更多 >
编程相关推荐