Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For Python 3.7+. 1. read a set of inventory items from a text file (LA1) 2. create a Python list for each item (LA1) 3.
For Python 3.7+.
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) 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.
- ) 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
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