对Python字典数组按Key求均值

2021-09-07 作者:

[ENG TITLE]: Calculate Mean Value by Keys in Python List of Nested-Dicts  

[OR]: Calculate Mean Value by Attributes in Python List of Objects

让我们考虑这样一种情况:现在你有个对象叫做“学生”,他们有年龄、身高、体重等多种数值属性。如何在不关心具体属性名称的前提下,采取简便手段计算多名学生任意属性的均值?

Let’s think about this case, say you have an object that represents single student of a group, and each student has at least his/her age, height, weight, and more attributes like these.

Now how to easily calculate mean value of each attribute within the student group, without caring about attribute names?

或许挺容易的,那么再考虑一下,如果给每名学生加个成绩单,成绩单里放着多科目成绩。以下级对象之实例作为上级实例属性,形成嵌套关系,此时怎么算最简洁呢?

Well, if it’s not a tough challenge, then let’s talk about those nested attributes (object as an attribute)?

完整阅读本篇»