python中的平均字典列表 [英] average list of dictionaries in python

查看:200
本文介绍了python中的平均字典列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的字典列表

data = [{'Name': 'john', 'Height': 176, 'Weight':62, 'IQ':120,..},...]

..表示各种其他整数/浮动属性,列表的所有元素都具有相同的格式。

the .. signifies various other integer/float attributes and all elements of the list has same format..

我想获得平均高度,重量和所有其他数字属性在最干净/最简单的方式。

I want to get the average Height, Weight and all other numerical attributes in the cleanest/easiest way.

我无法想出一个更好的方式比正常的循环太糟糕了...我不想使用任何外部包

I could not come up with a better way than normal for looping which was too messy... and i don't want to use any external packages

推荐答案

您可以使用以下

sum([item['Weight'] for item in data])/len(data)

并使用

float(len(data)) 

如果您想要更精确的值。

if you want a more exact value.

这篇关于python中的平均字典列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆