Question

In: Computer Science

Please code the following prompt in python. Today you will be building a movie/actor lookup. The...

Please code the following prompt in python.

Today you will be building a movie/actor lookup. The data structure that will power your lookups will be a dictionary which maps movies (as strings) to a list of actors (you may also use a set if you prefer). You will also add features such as finding the most common actor in a data set, or the movies that two actors have been in.

The first function you should write is add_or_update_a_movie. This function takes the movie dictionary, a movie, and a list of actors. You will need this for all other functions, so complete this feature first. If a movie is added that doesn't exist in the dictionary yet, make a new entry. If it does exist, the list of actors should be added to the current list of actors, with no actors repeated.

All of the other functions in movies.py are explained in the documentation. The last function is for extra credit and will require some knowledge of recursive functions.

Incorporate a function that should have the signiture

def degrees_between(movie_dict, actor1, actor2):

and uses the following file to open and create a dictionary:

https://s3.amazonaws.com/mimirplatform.production/files/a5dac972-8c2d-4565-95be-4b036cb08e7b/movies_large.txt

Solutions

Expert Solution

I have completed the read function but no details given for recursive function degrees_between how to do that so i have skipped this


def add_or_update_a_movie(movies, movie_name, actors):
    # checking if movie name is in list
    if movie_name not in movies:
        # if not adding entry
        movies[movie_name] = list(set(actors))
    else:
        # if movie name already found adding actor list to existing , by using set removing duplicate
        movies[movie_name] = list(set(movies[movie_name].extend(actors)))


if __name__ == '__main__':
    # name of file to be read
    # TODO: update the file as per your directory
    file_name = 'movies_large.txt'
    movies = {}
    with open(file_name, encoding='utf-8') as f:
        while f:
            line = f.readline().strip()
            if line:
                split_entry = list(map(str.strip, line.split(',')))
                # calling function with attributes
                add_or_update_a_movie(movies, split_entry[0], split_entry[1:])
            else:break
    print(movies)

# OUT

{'15 Minutes (2001)': ['Edward Burns', 'Robert De Niro'], '16 Blocks (2006)': ['Bruce Willis'], '21 Grams (2003)': ['Rodrigo Prieto', 'Naomi Watts'], '25th Hour (2002)': ['Edward Norton', 'Rosario Dawson', 'Brian Cox', 'Rodrigo Prieto'], '28 Days (2000)': ['Steve Buscemi'], '40 Days and 40 Nights (2002)': ['Elliot Davis', 'Josh Hartnett'], '50 First Dates (2004)': ['Adam Sandler', 'Drew Barrymore', 'Rob Schneider'], '8 Mile (2002)': ['Brittany Murphy', 'Rodrigo Prieto'], 'Abandon (2002)': ['Matthew Libatique', 'Benjamin Bratt', 'Zooey Deschanel'], 'About a Boy (2002)': ['Rachel Weisz', 'Toni Collette'], 'Adventures of Pluto Nash': ['Oliver Wood', 'Alec Baldwin', 'Rosario Dawson', 'Luis Guzm√°n', 'Eddie Murphy'], 'Adventures of Rocky & Bullwinkle': ['Robert De Niro', 'Rick Kain', 'Janeane Garofalo', 'Thomas Ackerman'], 'Affair of the Necklace': ['Hayden Panettiere', 'Brian Cox', 'Christopher Walken'], 'After the Sunset (2004)': ['Edward Norton', 'Don Cheadle'], 'Agent Cody Banks (2003)': ['Hilary Duff', 'Keith David'], 'Agent Cody Banks 2: Destination London (2004)': ['Anthony Anderson'], 'Alex & Emma (2003)': ['John Tobin', 'Luke Wilson'], 'Alexander (2004)': ['Angelina Jolie', 'Rodrigo Prieto', 'Anthony Hopkins']}
..... more out put


Related Solutions

Python: I want to make the following code to prompt the user if want to run...
Python: I want to make the following code to prompt the user if want to run the software again. I am new to python, so i do not know if it works like c++. If can explain that would be much appreciated base = float(input("Enter base of the triagle: ")) Triangle_Right = float(input("Enter right side of the triagle: ")) Triangle_Left = float(input("Enter left side of the triagle: ")) height = float(input("Enter the height of the triangle: ")) perimiter = base...
can you please convert this python code into java? Python code is as shown below: #...
can you please convert this python code into java? Python code is as shown below: # recursive function def row_puzzle_rec(row, pos, visited):    # if the element at the current position is 0 we have reached our goal    if row[pos] == 0:        possible = True    else:        # make a copy of the visited array        visited = visited[:]        # if the element at the current position has been already visited then...
Prompt: Produce a 4th order Runge Kutta code in PYTHON that evaluates the following second order...
Prompt: Produce a 4th order Runge Kutta code in PYTHON that evaluates the following second order ode with the given initial conditions, (d^2y/dt^2) +4(dy/dt)+2y=0, y(0)=1 and y'(0)=3. After your code can evaluate the 2nd order ode, add a final command to plot your results. You may only use python.
1. Please program the following in Python 3 code. 2. Please share your code. 3. Please...
1. Please program the following in Python 3 code. 2. Please share your code. 3. Please show all outputs. Instructions: Run Python code  List as Stack  and verify the following calculations; submit screen shots in a single file. Postfix Expression                Result 4 5 7 2 + - * = -16 3 4 + 2  * 7 / = 2 5 7 + 6 2 -  * = 48 4 2 3 5 1 - + * + = 18   List as Stack Code: """...
HOW WOULD YOU WRITE THIS IN PYTHON? SHOW THIS IN PYTHON CODE PLEASE # DEFINE 'all_keywords',...
HOW WOULD YOU WRITE THIS IN PYTHON? SHOW THIS IN PYTHON CODE PLEASE # DEFINE 'all_keywords', A LIST COMPRISED OF ALL OUR NEGATIVE SEARCH KEYWORDS AS REQUIRED BY THE PROJECT # FOR EACH ELEMENT IN 'full_list' (THE LIST OF LISTS YOU WOULD HAVE CREATD ABOVE THE PREVIOUS LINE) # INITIALIZE THE SET 'detected_keywords' TO EMPTY # DEFINE VARIABLE 'current_reviewer' FROM CURRENT ELEMENT OF 'full_list' BY EXTRACTING ITS FIRST SUB-ELEMENT,... # ...CONVERTING IT TO A STRING, AND THEN STRIPPING THE SUBSTRING...
Please support with a python response. The prompt was: To locate a link on a webpage,...
Please support with a python response. The prompt was: To locate a link on a webpage, we can search for the following three things in order: - First, look for the three character string '<a ' - Next, look for the following to close to the first part '>': Those enclose the URL - Finally, look for three characters to close the element: '</a': which marks the end of the link text The anchor has two parts we are interested...
*** Using Python *** Your program must prompt the user for their city or zip code...
*** Using Python *** Your program must prompt the user for their city or zip code and request weather forecast data from openweathermap.org. Your program must display the weather information in an READABLE format to the user. Requirements: Create a Python Application which asks the user for their zip code or city. Use the zip code or city name in order to obtain weather forecast data from: http://openweathermap.org/ Display the weather forecast in a readable format to the user. Use...
This code needs to be in C++, please. Step 1: Add code to prompt the user...
This code needs to be in C++, please. Step 1: Add code to prompt the user to enter the name of the room that they are entering information for. Validate the input of the name of the room so that an error is shown if the user does not enter a name for the room. The user must be given an unlimited amount of attempts to enter a name for the room. Step 2: Add Input Validation to the code...
I would like the following code in PYTHON please, there was a previous submission of this...
I would like the following code in PYTHON please, there was a previous submission of this question but I am trying to have the file save as a text file and not a json. Any help would be greatly appreciated. Create an application that does the following: The user will enter product codes and product numbers from the keyboard as strings. The product code must consist of four capital letters. The product number can only consist of numeric characters, but...
Python Code: Write a program to prompt the user to enter a first name, last name,...
Python Code: Write a program to prompt the user to enter a first name, last name, student ID, number of hours completed and GPA for 5 students. Use a loop to accept the data listed below. Save the records in a text file. Write a second program that reads the records from your new text file, then determines if the student qualifies for Dean’s list or probation. Display the records read from the file on screen with appropriate headings above...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT