这是我的字典列表:
array_of_dictionaries = [{
"name": "Budi",
"age": 23,
"test_scores": [100.0, 98.0, 89.0]
},
{
"name": "Charlie",
"age": 24,
"test_scores": [90.0, 100.0]
}]
这是我的代码:
def get_all_time_max_avg_score(dictionary_list):
for element in dictionary_list:
lensum = len(element['test_scores'])
elesum = sum(element['test_scores'])
meansum = elesum / lensum
for attribute in element.keys():
print("Mr. " + str(element['name']) + " with age(years) " + str(element['age']) + " get the highest average scores, " + str(round(meansum, 2)))
break
get_all_time_max_avg_score(array_of_dictionaries)
所以我想从这两个词典中获得最高的平均分。我想要的输出是:
Mr. Budi with age(years) 23 get the highest average scores, 95.67
但我得到的是:
Mr. Budi with age(years) 23 get the highest average scores, 95.67
Mr. Charlie with age(years) 24 get the highest average scores, 95.0
我真的很感激我能得到的每一个帮助。
LEATH
慕勒3428872
30秒到达战场
慕无忌1623718
饮歌长啸
相关分类