Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

file: jarlsberg, norway camembert, france mozzarella, italy edam, netherlands cotija, mexico pecorino romano, italy burrata, italy pecorino romano, italy feta, greece goat's cheese, france gruyere,

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

file: jarlsberg, norway camembert, france mozzarella, italy edam, netherlands cotija, mexico pecorino romano, italy burrata, italy pecorino romano, italy feta, greece goat's cheese, france gruyere, switzerland gouda, netherlands ossau-iraty, spain paneer, india parmesan, italy comte, france cotija, mexico reblochon, france stilton, england roquefort, france brie, france raclette, switzerland monterey jack, usa feta, greece gruyere, switzerland cashel blue, ireland brie, france stilton, england epoisses, france epoisses, france gorgonzola, france caerphilly, wales gruyere, switzerland roquefort, france cheshire, england gouda, netherlands cheddar, england monterey jack, usa reblochon, france reblochon, france taleggio, italy reblochon, france epoisses, france ossau-iraty, spain ossau-iraty, spain cotija, mexico mozzarella, italy camembert, france paneer, india manchego, spain jarlsberg, norway gorgonzola, france gorgonzola, france brie, france mascarpone, italy edam, netherlands reblochon, france goat's cheese, france manchego, spain buffalo mozzarella, italy provolone, italy feta, greece paneer, india cheshire, england paneer, india camembert, france edam, netherlands goat's cheese, france buffalo mozzarella, italy cotija, mexico taleggio, italy paneer, india cheddar, england taleggio, italy parmesan, italy vacherin mont d'or, switzerland mozzarella, italy cashel blue, ireland feta, greece caerphilly, wales gruyere, switzerland parmesan, italy comte, france goat's cheese, france goat's cheese, france gruyere, switzerland vacherin mont d'or, switzerland pecorino romano, italy burrata, italy burrata, italy monterey jack, usa ossau-iraty, spain gouda, netherlands feta, greece pecorino romano, italy monterey jack, usa paneer, india

solve with python please

But oh no! Their file was corrupted. Cheeses were duplicated, and there appear to be tabs at the beginning of most lines: roquefort, france roquefort, france mozzarella, italy epoisses, france mozzarella, italy It will take hours to fix this by hand : We need to know which cheeses come from each country. While Matt drives to Jungle Jim's International Market, help Erika read the file, process it, and print something where the countries are in alphabetical order, and the cheeses from each country are also in alphabetical order: france: epoisses roguefort italy: mozzarella We will be tight on time, so we should also direct Matt based on which countries have the most cheeses: [( 'france ', 2), ('italy', 1)] The purpose of this assignment is to gently get you back up to speed with Python concepts learned in I210, specifically opening data files, reading the contents into data structures, processing the data, and outputting them in a usable format. Practice writing functions that take an input and return an output. When completed, all of your functions should work together to fix the input file! PS 4.1 - Read data in from a file (5 points) - Implement to read in the contents a file (e.g. using try/except PS 4.2 - Format that data into a nested list (5 points) - Implement | to convert a string (with spaces, tabs, newlines, and commas) into lists-of-lists-of-strings: [[ 'roquefort', ' 'france'], ['roquefort', 'france']] PS 4.3 - Create a dictionary from a nested list (5 points) - Implement that returns a dictionary mapping from strings to lists of unique values. - Treat each item in the input as (value, key) pairs - Make sure the lists only contain unique values! >> nested_lists_to_dictC[["roquefort", "france"], ["roquefort", "france"], ["feta", "greece"], ["brie", "france"]]) { \{'france': ['roquefort', 'brie'], 'greece': ['feta']\} PS 4.4 - Convert the dictionary of lists to a human-readable format (5 points) - Implement that converts the dict of lists to a string. - Keys should be sorted PS 4.4 - Convert the dictionary of lists to a human-readable format (5 points) - Implement that converts the dict of lists to a string. - Keys should be sorted - Values that each key maps to should also be sorted - As with the other functions, this function should return a string, it should not directly print the result! >> print(format_dict_of_lists(\{'france' : ['roquefort', 'brie'], 'greece': ['feta', 'hatloumi ']\})) france: brie roquefort greece: feta halloumi PS 4.5 - Summarize the dictionary into tuples sorted by the number of values ( 5 points) - Implement to return a list of tuples - Each tuple should contain a key from the dictionary and the length of its list - The output should be sorted from greatest to least, according to how big each list was: >> summarize_dict_of_lists(\{'france' : ['roquefort', 'brie'], 'greece': ['feta']\}) [('france', 2), ('greece', 1)] PS 4.6 - Run the main module to help Matt and Erika fix the file! (5 points) Un-comment the last four lines of your script using or if ___name__ ==" nheeses = nested_lists_to_dict(to_nested_list(safe_load_file("cheeses-corrupted.txt")) print(format_dict_of_lists(cheeses)) print(summarize_dict_of_lists(cheeses))

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

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions