Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

My dictionary as of now is like this:

class_1 = {'Bob':[9,5,4,3,3,4], 'John':[5,5,7,3,6], 'Andy':[7,5,6,4,5], 'Harris':[3,4,2,3,2,3,2]}

What i am trying to make it look like is this:

class_1_average ={'Bob':[average of scores],'John':[average of scores].........

How can i do this so that even when the scores updates the average also updates with it. And is there also a way to find the highest score out of the scores

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
185 views
Welcome To Ask or Share your Answers For Others

1 Answer

try like this:

class_1_average = {key: sum(value)/len(value) for key, value in class_1.items()}

For max value: you can use max built-in function over the value of dictionary

max_each = {key: max(value) for key, value in class_1.items()}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...