我有这个代码:
new = {'a': 1, 'b': 2}
old = {'a': 1, 'c': 3}
added = new.keys() - old.keys()
if added:
print('{} keys have been added'.format(len(added)))
removed = old.keys() - new.keys()
if removed:
print('{} keys have been removed'.format(len(removed)))
# added, removed = minus_dict(new, old)
我必须做两次减法运算。minus_dict 函数是否存在?我的意思是如何以更有效的方式找到添加和删除?