Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is the program that I have to refractor....... def read_file(file_name): with open(file_name, 'r') as f: return [line.strip() for line in f] def recorder_groceries(groceryList, canonicalList):

image text in transcribedimage text in transcribed

image text in transcribed

Here is the program that I have to refractor.......

def read_file(file_name): with open(file_name, 'r') as f: return [line.strip() for line in f] def recorder_groceries(groceryList, canonicalList): return sorted(groceryList, key = lambda x: canonicalList.index(x)) if __name__ == '__main__': groceryList = read_file('groceries.txt') canonicalList = read_file('canonical.txt') print('Your Original Order:') print(*groceryList, sep = ' ') recorded_groceries = recorder_groceries(groceryList, canonicalList) print() print('Your Canonical Order:') print(*recorded_groceries, sep = ' ')
HoneyDoToo: Saving Your Relationship Once Again 10 Possible Points Due: Fri Feb 10, 2023 1:59pm IN PROGRESS Next Up: Submit Assignment Unlimited Attempts Allowed Details Scenario: You recently developed a program called HoneyDo which will reorder a list of groceries based on a provided canonical item ordering. However, you notice over time that is has become tiresome to list the items in canonical order (that list is pretty large). On top of that, you have since discovered that you can scrape the website of the grocery store to obtain an inventory of each item with its category listed. You decide to use this inventory to your advantage by changing your canonical list to only store the category of the items you would encounter as you traverse the store in your preferred order (a much smaller list). Your assignment: Refactor your HoneyDo program into a new program called HoneyDooToo which reorders a list of groceries based on a set of canonical categories and a provided store inventory. Your program must read a list of groceries from a text file called "groceries.txt" wherein each item to be purchased is listed on its own line of a file (shown below). Your program should also read a separate file called "canonical.txt" which lists the sequence of all the grocery store categories that you might encounter in their "canonical" ordering (also shown below). Finally, your program should also read the contents of a file called "inventory.txt" which lists the items and categories of each item for sale in the store. The output of your program is printed to the screen and shows both the original grocery list as well as the canonically re-ordered list by category (again, also shown below). Example of groceries.txt: \# ignore comments lines that start with '\#' milk wheat bread onions cap'n crunch ice cream toothpaste apples pizza ketchup mtn. dew Example of canonical.txt \# ignore comments lines that start with '\#' produce deli soft drinks breads cereal toiletries condiments dairy frozen An example of inventory.txt: \# ignore comments lines that start with '\#' breads: wheat bread condiments: ketchup condiments: mustard dairy: cheese dairy:ice cream dairy:milk deli:bologna deli:chicken frozen:burritos frozen:pizza cereal:cap' n crunch produce:apples produce:bananas produce: onions soft drinks:mtn. dew toiletries: toothpaste The output of the program is below

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions