我有4个字典,其中symbol
作为键,LTP
作为值。现在我想创建一个新的字典,其中symbol
作为我的键,4字典的LTP
的平均值作为我的值
first = {"MRF":40000,"RELIANCE":1000}
second = {"MRF":50000,"RELIANCE":2000}
third = {"MRF":30000,"RELIANCE":500}
fourth = {"MRF":60000,"RELIANCE":4000}
new = {"MRF":45000,"RELIANCE":1875} # this is the average of ltp
请帮我想个办法好吗
我们可以使用统计库和列表理解中的均值方法得到这个结果
代码如下:
注意:假设所有字典中的键都相同:
注意:我将Python3.x用于以下代码:
它会产生与您所需完全相同的结果
相关问题 更多 >
编程相关推荐