Question
Python: Creating a list of dicitionaries from lists in a text file and then searching the created list by dicitonary parameters. Please help! I'm lost
Python: Creating a list of dicitionaries from lists in a text file and then searching the created list by dicitonary parameters.
Please help! I'm lost at the moment..
So far this is the code I have for creating the list of dictionaries.
movies_list = [] dict1 = {} file_ref = open("movies.txt", 'r') line = file_ref.readline() #to skip first line with title headings for line in file_ref: movie_data = line.split("\t") dict1["title"] = movie_data[0] dict1["year"] = movie_data[2] dict1["length"] = movie_data[3] dict1["rating"] = movie_data[4] dict1["action"] = movie_data[4][1] == 1 dict1["animation"] = movie_data[4][2] == 1 dict1["comedy"] = movie_data[4][3] == 1 dict1["drama"] = movie_data[4][4] == 1 dict1["documentary"] = movie_data[4][5] == 1 dict1["romance"] = movie_data[4][6] == 1 movies_list.append(dict1) file_ref.close()
But I'm not sure how to repeat this process to create the new list of dictionaries.
Here is my assignment:
The python program to convert this from is located here: http://s000.tinyupload.com/index.php?file_id=84642422187616669012
The movie text file I'm using is located here: http://s000.tinyupload.com/?file_id=48953557772434487729
Thank you in advance for any help.
Movie Selector (with dictionaries) We have already created a movie selector in Project Assignment 3. In this project assignment, you need to create another (better) version of this program which uses a dictionary to record each movie. Program Design Your program must contain and use the methods listed below. Feel free to add any parameters in the function definitions. Feel free to add other methods as you see fit. # (new requirement) load all the movies in the file into a list of dictionaries. Each dictionary keeps the information for one movie. load movies() #List all movie titles the total number of movies list_movies() #Prompt the user for a year and list all movie titles for that year list_by_year() #Prompt the user for part or all of title and #list all movie titles that contain that substring ignoring case search_by_title() #Prompt the user for a rating, genre, and maximum length and #list all movie titles that meet the criteria search) The new function, load movies will recursively read each line from the file, prepare a dictionary for the current movie, and append the dictionary to a list of dictionaries called movie info For each dictionary of each movie, you should create the following keys: O Title ? Year Movie Selector (with dictionaries) We have already created a movie selector in Project Assignment 3. In this project assignment, you need to create another (better) version of this program which uses a dictionary to record each movie. Program Design Your program must contain and use the methods listed below. Feel free to add any parameters in the function definitions. Feel free to add other methods as you see fit. # (new requirement) load all the movies in the file into a list of dictionaries. Each dictionary keeps the information for one movie. load movies() #List all movie titles the total number of movies list_movies() #Prompt the user for a year and list all movie titles for that year list_by_year() #Prompt the user for part or all of title and #list all movie titles that contain that substring ignoring case search_by_title() #Prompt the user for a rating, genre, and maximum length and #list all movie titles that meet the criteria search) The new function, load movies will recursively read each line from the file, prepare a dictionary for the current movie, and append the dictionary to a list of dictionaries called movie info For each dictionary of each movie, you should create the following keys: O Title ? YearStep 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