Question: using python coding: 1. (25 points total) Given a set of car inventory information read from a file and converted to a list, write a
1. (25 points total) Given a set of car inventory information read from a file and converted to a list, write a Python function to accept the car list as input and return a "reverse" dictionary. A partial list of car information is given below: carList = [["Honda", "Accord", 2014, 62000], ["Toyota", "Camry", 2015, 43500], ["Ford", "Focus", 2013, 58000], ["Honda", "Civic", 2012, 71000]. ] The data is a list of lists and includes the manufacturer of the car (e.g. "Honda"), the model, year, and mileage. To facilitate looking up cars in the inventory, the reverse dictionary should be built from the list by reading each sub-list (e.g. ["Honda", "Accord", 2014, 62000]) and use the manufacturer ("Honda") as the dictionary key. The other elements in the list ("Accord", 2014, and 62000) are the values for the particular key. Recall that you have two cases your code needs to handle: (1) the key is not already in the dictionary, and (2) the key is already there. The logic and code are very similar to that used to build the dictionary for A1. To get you started I've supplied the first lines and return statement. You only need to provide the code in the middle. def buildDict (carList): Dict = {} # Name of the dictionary to be built - initially empty %3D # insert code below
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
