Search⌘ K

Solution Review: Extracting Toppers From a Student Record

Explore how to use Python list comprehensions and conditional statements to extract student names who scored above 80 percent. This lesson helps you apply traversal and filtering techniques on lists of dictionaries to efficiently identify top performers in student records.

We'll cover the following...

Solution

Python 3.5
def get_top(grades):
return [x['name'] for x in grades if x['percent'] >= 80]
grades = [
{"name": "Mary","percent": 90},
{"name": "Don","percent": 55},
{"name": "Bob","percent": 70},
{"name": "Jim","percent": 85},
{"name": "Meg","percent": 80},
{"name": "Jil","percent": 75}
]
print(get_top(grades))

Explanation

To solve this problem, we used the list comprehension syntax.

First of ...