- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Suppose we have a dictionary of students marks. The keys are names and the marks are list of numbers. We have to find the average of each students.

So, if the input is like scores = {'Amal' : [25,36,47,45],'Bimal' : [85,74,69,47],'Tarun' : [65,35,87,14],'Akash' : [74,12,36,75]}, then the output will be [38.25, 68.75, 50.25, 49.25] so 38.25 is average score for Amal, 68.75 is average score for Bimal and so on.

To solve this, we will follow these steps −

- avg_scores := a new map
- for each name in scores dictionary, do
- avg_scores[name] := average of scores present in the list scores[name]

- return list of all values of avg_scores

Let us see the following implementation to get better understanding

def solve(scores): avg_scores = dict() for name in scores: avg_scores[name] = sum(scores[name])/len(scores[name]) return list(avg_scores.values()) scores = {'Amal' : [25,36,47,45],'Bimal' : [85,74,69,47],'Tarun' : [65,35,87,14],'Akash' : [74,12,36,75]} print(solve(scores))

[['Amal',37],['Bimal',37],['Tarun',36],['Akash',41],['Himadri',39]]

[38, 68, 50, 49]

- Related Questions & Answers
- Python program to find word score from list of words
- Python program to get maximum of each key Dictionary List
- Python program to find score and name of winner of minion game
- Program to find maximum score from removing stones in Python
- Aggregation framework to get the name of students with test one score less than the total average of all the tests
- How to find the average of non-zero values in a Python dictionary?
- Program to find minimum difference of stone games score in Python
- Program to find maximum score of a good subarray in Python
- Program to find maximum score of brick removal game in Python
- Find out the records of students with more than a specific score in MySQL?
- Python program to find runner-up score
- Find average of each array within an array JavaScript
- Program to find maximum score from performing multiplication operations in Python
- Program to find sum of the minimums of each sublist from a list in Python
- Find average of each array within an array in JavaScript

Advertisements