我想计算列表中“分数”(字典值)的中位数
my_dict = {"John": [{"class": "math", "score": 100, "year": 2014}, {"class": "english", "score": 85, "year": 2015}, {"class": "science", "score": 90, "year": 2015}],
"Timmy": [{"class": "math", "score": 87, "year": 2014}, {"class": "english", "score": 91, "year": 2015}],
"Sally":[{"class": "math", "score": 95, "year": 2014}]}
输出如下所示:
new_dict = {"John": 90, "Timmy": 89, "Sally": 95}
我想我需要根据分数对我的字典进行排序,然后计算中值。如果不使用外部软件包,就无法完全理解这两个步骤
任何帮助都将不胜感激!Python新手
输出:
您可以使用numpy.median来计算中位数
您可以使用来自statistics的中间值
如果不想使用软件包编写自己的函数,可以调用:
使用median和dict理解的一行程序
输出:
相关问题 更多 >
编程相关推荐