python - Get the average of a list for each key in a dict -


i have defaultdict maps names list of scores. need work out average scores of students.

scores = {"aaron" : ["1" , "3" , "4"] , "joe" : ["3" , "7" , "2"] , "bob" : ["7" , "4" , "8"]} 

how can averages in new dict?

averages = {"aaron" : 2.7 , "joe" : 4 , "bob" : 13.7} 

convert each value string float, take average, , build new dict.

scores = {"aaron" : ["1" , "3" , "4"] , "joe" : ["3" , "7" , "2"] , "bob" : ["7" , "4" , "8"]} averages = {key: sum(float(i) in value) / len(value) key, value in scores.items()} 

Comments