Question: Using python Function name: write_to_json Parameters: file_name (str), combined_list (list) Return Type: dict Description: Write a function that takes in combined_list (see test case) and

Using python

Function name: write_to_json

Parameters: file_name (str), combined_list (list)

Return Type: dict

Description: Write a function that takes in combined_list (see test case) and writes a dictionary to a new JSON file created from the file_name parameter (again, WITHOUT file extension) with the following keys and values:

Key i the ith unique release_year where i = 1, 2, (str)

Value i list of dictionaries corresponding to each movie/show:

Key 1 date_added. If date_added is None, skip and move onto the next movie/show

Value 1 date the movie/show was added (str)

Key 2 title

Value 2 the title of the movie/show (str)

Key 3 show_id

Value 3 The corresponding show id (int)

Key 4 director

Value 4 The corresponding director(s) (str)

Key 5 num_countries

Value 5 Number of countries the movie/show was produced in. If country is Unknown, set the value to 0 (int)

You should sort combined_list based on the release_year in descending order first. You should also sort each list of dictionaries by show_id in ascending order before writing the dictionary to your JSON file. Do not include any movie/shows with the dated_added of None. Return the Python dictionary after you are finished. Example of what your returned dictionary might look like

Test Case:

>>> cleaned_csv_list = read_and_clean_csv('netflix')

>>> cleaned_json_list = read_and_clean_json('netflix')

>>> combined_list = cleaned_csv_list + cleaned_json_list

>>> write_to_json('combined_netflix', combined_list)

{ "2020": [ { "date_added": "01-03-2020", "title": "All the Freckles in the World", "show_id": 81006825, "director": "Yibr\u00e1n Asuad", "num_countries": 1 }, { "date_added": "11-13-2019", "title": "Maradona in Mexico", "show_id": 81034946, "director": None, "num_countries": 3 }, { "date_added": "01-01-2020", "title": "Ghost Stories", "show_id": 81088083, "director": "Anurag Kashyap, Dibakar Banerjee, Karan Johar, Zoya Akhtar", "num_countries": 1 } ], "2019": [ { "date_added": "09-19-2019", "title": "The Blacklist", "show_id": 70281312, "director": None, "num_countries": 1 }, ... ], ... , "1942": [ { "date_added": "03-31-2017", "title": "Prelude to War", "show_id": 60027945, "director": "Frank Capra", "num_countries": 1 } ] }

f{file_name}.json looks like

Using python Function name: write_to_json Parameters: file_name (str), combined_list (list) Return Type:

"2020": [ "date_added":"01-03-2020", "title": "All the Freckles in the World", "show id: 81006825, "director": "Yibr\u00e1n Asuad", "num countries": 1 "date_added": "11-13-2019", "title": "Maradona in Mexico", "show_id" : 81034946, "director": null, "num countries": 3 "date_added": "01-01-2020" "title": "Ghost Stories", "show_id" : 81088083, "director": "Anurag Kashyap, Dibakar Banerjee, Karan Johar, Zoya Akhtar", "num_countries": 1 "2019": [ "date_added":"09-19-2019", "title":"The Blacklist", "show_id": 70281312, "director": null, "num_countries": 1 "2020": [ "date_added":"01-03-2020", "title": "All the Freckles in the World", "show id: 81006825, "director": "Yibr\u00e1n Asuad", "num countries": 1 "date_added": "11-13-2019", "title": "Maradona in Mexico", "show_id" : 81034946, "director": null, "num countries": 3 "date_added": "01-01-2020" "title": "Ghost Stories", "show_id" : 81088083, "director": "Anurag Kashyap, Dibakar Banerjee, Karan Johar, Zoya Akhtar", "num_countries": 1 "2019": [ "date_added":"09-19-2019", "title":"The Blacklist", "show_id": 70281312, "director": null, "num_countries": 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!