Question: basic python json question. You may assume that function list_of_lists_to_list_of_dicts is already written and can be called directly ## Question 3 - Given the following
basic python json question. You may assume that function "list_of_lists_to_list_of_dicts" is already written and can be called directly
## Question 3 - Given the following data, .. names = [("Tom", "Brady"), ("Drew", "Brees"), ("Aaron", "Rogers"), ("Joe", "Montana"), ("Dan", "Marino")], ages = [42, 40, 36, 63, 58] - Combine the names and ages to a list of lists in the following format - [["fname", "lname", "age"], ["Tom", "Brady", 42] . ) - Convert the list of lists to list of dictionaries using list_of_lists_to_list_of_dicts - Create a json formatted dictionary that with the following format: The number of keys for the outermost dictionary should be 'Retired' and 'Active'. A quarterback is considered 'Retired' if their 'age' is greater than 40, and 'Active' otherwise. Refer to the example for the proper format - Each value of the dictionary should be sorted by age in ascending order - Write the json to the filename, file name will include the extension (e.g. "filename.json") - Return the dictionary that is associated with the outputted json file - You MAY hard code the keys "fname","lname", and "age". - e.g. >> names [("Tom", "Brady"), ("Drew", "Brees"), ("Aaron", "Rogers"), ("Joe", "Montana"), ("Dan", "Marino")] >> ages = [42, 40, 36, 63, 58] >> print(abs_to_json (names, ages, 'output.json')), {"Retired": [{"fname": "Tom", "lname" : "Brady", "age" : 42}, {"fname": "Joe", "iname" : "Montana", "age" : 63}, ...), "Active": [{"fname" : "Aaron", "lname" : "Rogers", "age" : 36}, {"fname" : "Drew", "lname" : "Brees", "age" :40}, def gbs_to_json(names, ages, filename)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
