小编sta*_*ser的帖子

如何将字典中的列表元素相乘

我有两个字典,如下所述,我需要将字典列表中的每个元素与其他字典列表中的相应元素相乘并打印结果。我已经成功地增加了一个列表,如何使其动态化?

dict1 = {0: [1, 1, 0, 1, 1, 0], 1: [1, 0, 1, 1, 1, 0]}

dict2 = { 0: [16, 0, 2, 0, 0, 0], 1: [15, 0, 0, 0, 1, 0]}

result = { 0: [16, 0, 0, 0, 0, 0], 1:[15, 0, 0, 0, 1, 0]}

from operator import mul
result = list( map(mul, dict1[0], dict2[0]) )
Run Code Online (Sandbox Code Playgroud)

python dictionary list list-manipulation

3
推荐指数
1
解决办法
1418
查看次数

标签 统计

dictionary ×1

list ×1

list-manipulation ×1

python ×1