Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am having trouble with a programming assignment. Although this code runs well without errors, I am having a problem with getting it to compute
I am having trouble with a programming assignment.
Although this code runs well without errors, I am having a problem with getting it to compute the results that my professor said it has to produce.
''' HoneyDo: Saving Your Relationship One Program at a Time by: Robby Osborne 1/28/2023 CS-2343: Advanced Scripting ''' def read_file(file_name): with open(file_name, 'r') as f: return [line.strip() for line in f] def reorder_groceries(groceries, canonical): return sorted(groceries, key=lambda x: canonical.index(x)) if __name__ == '__main__': groceries = read_file('groceries.txt') canonical = read_file('canonical.txt') print('Your Original Order:') print(*groceries, sep=' ') reordered_groceries = reorder_groceries(groceries, canonical) print('Your canonical Order:') print(*reordered_groceries, sep=' ')
Is there a way to modify it so that instead of producing this result.....
It produces this result, where there is a space between the separate orders?
Your Original Order: milk bread onions cereal ice cream toothpaste apples frozen pizza Your canonical Order: apples onions bread cereal toothpaste frozen pizza milk ice cream The output of the program is below: Your Original Order: milk bread onions cereal ice cream toothpaste apples frozen pizza Your canonical Order: apples onions bread cereal toothpaste frozen pizza milk ice creamStep 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