Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python: deleting dictionaries from a list I\'m trying to delete dictionaries fro

ID: 3721124 • Letter: P

Question

Python: deleting dictionaries from a list

I'm trying to delete dictionaries from a list that fit my parameters.

Here is my current code, I've commented where I'm having a problem.

This code works from the movie.txt file located here: http://s000.tinyupload.com/?file_id=48953557772434487729

Basically the program takes the info from the txt file and then converts the lists of each file into a dicitonary and puts them into a list. From this list, I'm trying to sort out and exclude the things I don't need. I thought my sytax was right, but apparently not.

I only included neccessary code to cut down on the clutter. I am having probems at the "action" point and excluding and deleting the dictionaries there. When prompted enter "s" and then "a" to access those two menus.

Each dictionary in the list looks like this:

Thank you again for help! I can't figure this out!

For example, from the dataset, the information of the first movie is: $ 1971 121 NR 001100 A dictionary below should be built for this movie: {"Title": "S", "Year": 1971, "Length": 121, "Rating": "NR", "Action": False, "Animation": False, "Comedy" True, "Drama": True, "Documentary" False, "Romance": False)

Explanation / Answer

From the limited information available in the question we infer that the dictionary current is having parameters as Current ={ Title : "Title_name " , " Year" : "Year_val" , "Length" : "length_val" , "Rating" : "Rating_val" , "Action" : "Value" , "Animation " : "Value" , "Comedy " : "Value" , "Drama" : "Value" , "Documentary " : "Value" , "Romance": "Value" }

The intent is to check the value of key 'Action' in the dictionary 'current' . If the value of the key 'Action' is equal to 'False' then delete the dictionary

For the above an alternate code to meet the requirement could be :

You can also try using the get() method as below:

It seems json.dumps() has been used to convert the dictionary items( keys and values) to string