Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Current functions for the question: def reviewer_rank(db : {str:{(str,int)}}) -> [(str,int)]: pass def reviewer_nested_dict(db : {str:{(str,int)}}) -> {str:{str:int}}: pass 5. (6 pts) Netflix stores a
Current functions for the question:
def reviewer_rank(db : {str:{(str,int)}}) -> [(str,int)]: pass
def reviewer_nested_dict(db : {str:{(str,int)}}) -> {str:{str:int}}: pass
5. (6 pts) Netflix stores a database that we can represent as a dict, whose keys are movie titles like 'Pscyho' (str); associated with each title is a set of 2-tuples. Each 2-tuple specifies the name of a reviewer (str) followed by his/her score (int: a number 0-5); for example ('Bob', 5). A simple/small database can look like Psycho': ('Bob', 5), ('Carry', 5), ('Diane', 1)), 'Amadeus': f('Bob', 3), ('Carry', 3), ('Diane', 3), [ ('Alan',2), 'Bob', 5), ('Diane', 5)) ) a. (3pts) Define the reviewer rank function to return a list of 2-tuples (reviewer name, number of reviews) sorted from highest to lowest number of reviews, with equal numbers listed alphabetically by reviewer. For example, if db is bound to the database above, calling reviewer_rank (db) returns the list [ ( 'Bob' , 3) , ( 'Diane' , 3) , ( 'Carry' , 2) , ( 'Alan' , 1) ] . Hint: I used a defaultdict b. (3 pts) Define the reviewer_nested dict function to return a dict whose keys are the reviewers, where each reviewer is associated with an inner dict whose keys are movies reviewed by that reviewer, with each movie associated with the reviewer's score for it. For example, if db is bound to the database above, calling reviewer nested dict (db) returns the dict ['Alan': ('Up': 2), 'Bob': ['Amadeus': 3, 'Psycho': 5, 'Up': 5], 'Carry': ('Amadeus': 3, 'Psycho': 5), 'Diane': ('Amadeus': 3, 'Psycho': 1, 'Up': 5] ) Of course, the inner and outer dicts can print their key/value associations in any order. Hint: I used a defaultdict to accumulate this information and then created/returned an equivalent dictStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started