Question: Q2 Write a function a filmography(L) whose parameter L is a list of tuples of the form (actor, movie) and creates and returns a dictionary
Q2 Write a function a filmography(L) whose parameter L is a list of tuples of the form (actor, movie) and creates and returns a dictionary where the keys are actor names and the values are lists of movies that actor has been in. For example, given L = tf'DiCaprio', 'Revenant), ('Cumberbatch', 'Hobbit'). (DiCaprio', 'Gatsby'), ("DiCaprio', 'Django) then you should return {'Dicaprio':l'Revenant', 'Gatsby", "Django). 'Cumberbatch': 'Hobbit'l} In YOUR CODE MERE raise Not Implementederror) In 1: Sanity checka L - (DiCaprio', 'Revenant' ('Cumberbatch', 'Bobbit) (DiCaprio', 'Gatsby'). (DiCaprio', 'Django 1 D = filmography (L) print(0) In 1: Testing cell L - (DiCaprio, "Revenant'). 'Cumberbatch', 'Hobbit) (DiCaprio', 'Gatsby), Dicaprio', 'Django D = filmography (L) assert len(D) - 2 assert DiCaprio in D. keys) assert 'Django in D 'Dicaprio assert 'Cumberbatch' In D. keys) assert DI'Cumberbatch - Hobbit'i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
