我有一个这样的字典列表:
[{
'name': 'John',
'birth': '1988',
'job': 'accountant',
'home': 'San Francisco'
}, {
'name': 'Kelly',
'birth': '1983',
'job': 'lawyer',
'home': 'LA'
}, {
'name': 'Bob',
'birth': '1972',
'job': 'driver',
'home': 'Chicago'
}, {
'name': 'Betty',
'birth': '1986',
'job': 'teacher',
'home': 'San Francisco'
}...]
我想做的是根据“家”键找到“出生”的平均值。理想情况下,这将是一个新的字典列表,根据家庭的不同,列出平均出生年份:
[{
'home': 'San Francisco',
'birth': (average of the birth year, of everyone in the list with the key 'home'
and value 'San Francisco')
}, ....]
我该怎么做?你知道吗
使用
defaultdict
将家庭分组,然后计算出生平均数输出
相关问题 更多 >
编程相关推荐