小编use*_*072的帖子

在Python中将两个不同字典的值相乘

我有两个单独的词典,其中包含键和值,我想将它们相加.这些值应该只乘以它们所拥有的键.

dict1 = {'a': 1, 'b': 2, 'c': 3}
dict2 = {'a': 15, 'b': 10, 'd': 17}

dict3 = dict.items() * dict.items()
print dict3

#### #dict3 should equal 
{'a': 15, 'b': 20}
Run Code Online (Sandbox Code Playgroud)

如果有人可以提供帮助,那就太好了.谢谢!

python dictionary matrix-multiplication

6
推荐指数
1
解决办法
7128
查看次数

标签 统计

dictionary ×1

matrix-multiplication ×1

python ×1