Answered step by step
Verified Expert Solution
Link Copied!

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.....

image text in transcribed

It produces this result, where there is a space between the separate orders?

image text in transcribed

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 cream

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

Step: 3

blur-text-image

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 3 Lnai 9286

Authors: Albert Bifet ,Michael May ,Bianca Zadrozny ,Ricard Gavalda ,Dino Pedreschi ,Francesco Bonchi ,Jaime Cardoso ,Myra Spiliopoulou

1st Edition

3319234609, 978-3319234601

More Books

Students also viewed these Databases questions