Question: Language: Python Topic: Dictionaries Function name: average_rating Parameters: dictionary containing NYC neighborhoods as keys and their values being a nested dictionary whose keys are tourist

Language: Python

Topic: Dictionaries

Function name: average_rating Parameters: dictionary containing NYC neighborhoods as keys and their values being a nested dictionary whose keys are tourist locations and values are a list of integer ratings

Returns: dictionary

Description: You want to find the best restaurants, tourist attractions, etc. in New York City based on their average ratings. Write a function that takes in a dictionary where the key is a specific New York City neighborhood and the value is a nested dictionary whose key is a tourist attraction and value is a list of integers representing the attractions ratings. The function should take use this dictionary to find the average rating for each individual tourist attraction rounded to two decimal places . Return a dictionary in the same formatting, but with the average rating of each attraction instead of a list of ratings.

>>> ratings1 = {"Brooklyn" : {"Coney Island": [9, 10, 8, 9], "DUMBO": [7, 7, 7, 8], "Brooklyn Bridge": [10, 5, 6]}, "The Bronx" : {"Yankee Stadium": [8, 4, 3, 3, 6]}} >>> avgratings1 = average_rating(ratings1) >>> print(avgratings1)

{'Brooklyn': {'Coney Island': 9.0, 'DUMBO': 7.25, 'Brooklyn Bridge': 7.0}, 'The Bronx': {'Yankee Stadium': 4.8}}

>>> ratings2 = {"Manhattan" : {"Central Park": [9], "MoMA" : [10, 6], "Empire State Building": [8, 5, 6]}, "Queens" : {"Queens Museum": [2, 3, 1, 8]}} >>> avgratings2 = average_rating(ratings2) >>> print(avgratings2)

{'Manhattan': {'Central Park': 9.0, 'MoMA': 8.0, 'Empire State Building': 6.33}, 'Queens': {'Queens Museum': 3.5}}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!