Best-Rated Restaurant

Easy ⏱ 8 min 82% acceptance ★★★★☆ 4.4
Write top_rated(restaurants) where each restaurant is a dict with 'name' and 'rating'. Return the name of the highest-rated one using max with a lambda key.

Examples

Example 1
Input
top_rated([{'name': 'A2B', 'rating': 4.4}, {'name': 'Leo', 'rating': 4.8}])
Output
'Leo'
Explanation

Leo has the higher rating.

Constraints

  • Use max with key=.
  • Assume a non-empty list.

Topics

Lambda & Functionalmax with key

Companies

ZomatoSwiggyUber

Hints

Hint 1

max picks by the key function's value.

Hint 2

Then read ['name'] off the winner.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.