Please answer this Python in the simplest way.
A1input.txt
B001,book,Patriot Games, 15.95 B002,book,Origin, 19.95 C001,cloth,Armani Suit, 800.00 B003,book,Animal Farm, 9.97 B004,book,Grant, 22.50 E001,elect,EyePhone 10,795.00 E002,elect,First Alert Smoke Alarm, 29.95 F001,food,Moose Drool Ale 6-pack, 9.95 C002,cloth,Pants, 39.95 B005,book,Prairie Fires, 18.95 E003,elect,Sony Prtable Radio, 15.00 C003,cloth,Vasque Hiking Boots, 109.00 C004,cloth,Wool Hat, 14.00 F002,food,Jumbo shrimp, 12.50 E004,elect,HP Laptop, 350.00 C005,cloth,Wrangler Jeans, 24.50 B005,book,Ragtime, 17.25 F003,food,Fusili - 16 oz., 2.95 C006,cloth,Nike T-shirt, 19.00 C007,cloth,Gore-Tex Gloves, 39.00 C008,cloth,North Face Fleece Jacket, 89.95 C009,cloth,Nationals Logo Sweatshirt, 49.00 E005,elect,LinkSys Router, 49.95 F004,food,Lamb Chops, 21.95 C010,cloth,New Balance Trail Runners,69.95 E006,elect,Altec Lansing Speakers, 195.95 B006,book,Future Shock, 8.95 E007,elect,LG 55 UDTV,350.00 E008,elect,Dell All-in-One PC, 495.00 E009,elect,Brother Laser Printer, 99.00
Transcribed Image Text: itemList = loadItems()
displayItems(itemList)
print(^\n\n')
DS = buildDict(itemList) # builds and returns the "reverse" dictionary from the input list
writeFile(DS)
# invoke function to read the file into a list, return the list
# takes list as input and prints it (this should be simple)
# inserts some separating spaces
# creates output file and writes records to it
Reverse Dictionary
The 'buildDict(<list>)' function reads each inventory item from the input list and takes one of the following
actions:
1. if the 'category' of the item read is not already in the dictionary, that category is added as a key and the
inventory number, description, and price are made into a list and inserted as a value of that category's key
2. if the 'category' of the item read is already in the dictionary, the inventory number, description, and price are
made into a list and appended to that key's value.
The resulting dictionary has as many entries as categories. Each entry is a list of lists. The master list includes
everything for the corresponding category, while each sub-list is the data for one particular inventory item.
An example of the dictionary for the 'book' category:
{book: [['B001', Patriot Games', 15.95], ['B002', 'Origin', 19.95], ... ['B006', 'Future Shock', 8.95]]}
Output File
The output file is a text file consisting of comma-separated data. The file name you create is "<Iname+1st
initial>Aloutput.txt" (example: "smithfAloutput.txt"), written to your default drive and directory. There is one
line per data item. Each line consists of (1) category, (2) inventory number, (3) description, and (4) price. The
reverse dictionary will supply these to your function.
Iterating through the reverse dictionary will yield lines like the ones below. When writing to the file write out
the dictionary key followed by inventory number, description, and price (brackets [' and ]’ will not be written
to the output file). The output is a set of comma-separated text strings.
book,B001,Patriot Games, 15.95
book,B002,Origin, 19.95
book,B003,Animal Farm, 9.97
book,B004,Grant, 22.50
book,B005,Prairie Fires, 18.95
book,B005,Ragtime, 17.25
book,B006,Future Shock, 8.95
cloth,C001,Armani Suit, 800.00
cloth,C002,Pants, 39.95
cloth,C003,Vasque Hiking Boots, 109.00
cloth,C004, Wool Hat, 14.00
cloth,C005,Wrangler Jeans, 24.50
cloth,C006,Nike T-shirt, 19.00
cloth,C007,Gore-Tex Gloves, 39.00
cloth,C008,North Face Fleece Jacket, 89.95
cloth,C009,Nationals Logo Sweatshirt, 49.00
cloth,C010,New Balance Trail Runners', 69.95
elect,E001,EyePhone 10, 795.00
elect,E002,First Alert Smoke Alarm, 29.95
Transcribed Image Text: This assignment serves as a review of several important Python features and capabilities you learned in the
previous course. In it you will create code to do the following (parentheses indicate which part of the
assignment is due in Lab 1, LA1, and which is due later as part of the class assignment A1):
1. read a set of inventory items from a text file (LA1)
2. create a Python list for each item (LA1)
3. display each item in the list (LA1)
4. build a "reverse" dictionary consisting of each item type as key and all items in that category as the
value (A1)
5. create an output file and write each item to it by iterating through the dictionary and writing by
category+item (A1)
Note that each of the above five items are to be implemented as separate functions. The 'file read' and 'list
build' should be implemented as one function, resulting in a total of four that you are to create.
Since this assignment has several parts, the first lab assignment will involve completing some of the above. So
this assignment counts for both the first lab and class assignments. Use the time in the lab to help complete part
of it.
Input File
You will be provided with an input file consisting of inventory items. The file name is “Alinput.txt". Each line
consists of comma-separated data: inventory number, category, description, and price. Part of the input file is
shown below. The actual file has additional lines. Note that the inventory number has 4 characters, the
category is in the set {“book", "elect", "cloth", and “food"}. The description is free text, up to 25 characters in
length. The price is floating point with only two digits to the right of the decimal.
<start of sample input>
BO01,book,Patriot Games, 15.95
BO02,book,Origin, 19.95
C001,cloth,Armani Suit, 800.00
BO03,book,Animal Farm, 9.97
B004,book,Grant, 22.50
E001,elect,EyePhone 10,795.00
E002,elect,First Alert Smoke Alarm, 29.95
FO01,food,Moose Drool Ale 6-pack, 9.95
C002,cloth,Pants, 39.95
B005,book,Prairie Fires, 18.95
E003,elect,Sony Portable Radio, 15.00
C003,cloth, Vasque Hiking Boots, 109.00
C004,cloth, Wool Hat, 14.00
FO02,food,Jumbo shrimp, 12.50
E004,elect,HP Laptop, 350.00
<end of sample input>
Functions
The separate functions to be implemented should be such that the global code is minimized. With most of the
program's action being handled by the functions the global code could be approximately this small:
itemList = loadItems()
displayItems(itemList)
print(^\n\n')
DS = buildDict(itemList) # builds and returns the "reverse" dictionary from the input list
writeFile(DS)
# invoke function to read the file into a list, return the list
# takes list as input and prints it (this should be simple)
# inserts some separating spaces
# creates output file and writes records to it