浙大版《Python 程序设计》题目集第5章-11 字典合并 (40 分)
转自:伶回合–Python编程PTA题解——字典合并
a = dict(eval(input()))
b = dict(eval(input()))
for k in b.keys():
a[k] = a.get(k, 0) + b[k]
t = list(a.items())
t.sort(key=lambda x : ord(x[0]) if type(x[0]) == str else x[0])
c = str(dict(t)).replace(' ', '').replace("'", '"')
print(c)
python中的get()和item()函数
Python的Lambda函数用法详解
python的sort()函数详解
Python的替换函数——strip(),replace()和re.sub()