题解 | 合并表记录
import sys
n = int(input())
dict = {}
for i in range(n):
temp =list(input().split())
key = int(temp[0])
value = int(temp[1])
dict[key] = dict.get(key,0) + value
#dict.get(key, default=None)
for i in sorted(dict):
print(i,dict[i])
dict.get(key, default=None)
key: 要查找的键。default: 如果键不存在时返回的默认值(默认为None)。
查看10道真题和解析
