Answered step by step
Verified Expert Solution
Question
1 Approved Answer
using python: ## Question 3 # - Given the following data, ... names = [(Tom, Brady), (Drew, Brees), (Aaron, Rogers), (Joe, Montana), (Dan, Marino)] ages
using python:
## 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 # 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(qbs_to_json(names, ages, 'output.json'))
# {"Retired":
# [{"fname": "Tom", "lname" : "Brady", "age" : 42},
# {"fname": "Joe", "lname" : "Montana", "age" : 63},
# ],
# "Active":
# [{"fname" : "Aaron", "lname" : "Rogers", "age" : 36},
# {"fname" : "Drew", "lname" : "Brees", "age" :40},
# ]
# }
def qbs_to_json(names, ages, filename):
Step 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