Python
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Python
![Food Quantities
File
You are a cook in a busy restaurant. You are writing a program to help you organize how much of each kind of food you need to cook. Naturally, you decide to
take a break from cooking and write a function to help. You decide that your function will take a dictionary as a parameter where the keys are the tables in the
restaurant and the values are lists of strings describing the food each table has ordered. Your function returns a dictionary with the totals for how many of each
food item you need to cook.
For example, say you have 5 tables and 3 dishes:
Tables: t1, t2, t3, t4 and t5
Dishes: Vegetarian stew, Steak pie, Poutine
Input:
You will use the table names as the keys, and use a list of the foods ordered at each table as values.
For example your dictionary may look like this:
{'t1': ['Vegetarian stew', 'Poutine', 'Vegetarian stew'],
't3': ['Steak pie', 'Poutine', 'Vegetarian stew'],
't4': ['Steak pie', 'Steak pie']}
Output:
Your function must return a dictionary with the dish as the key, and the number of times that dish was ordered as the value, Given the above input, your function
would create and return a dictionary equivalent to the following:
{'Vegetarian stew': 3, 'Poutine': 2, 'Steak pie': 3}
Here we have started the code for you. Complete it:
100%
10°C Mostly cloudy
nere to search](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F10c0e332-20ab-46ed-9fce-80292c993027%2F83fe196d-b261-4421-80ac-33f19817c562%2Ffcp6iai_processed.jpeg&w=3840&q=75)
Transcribed Image Text:Food Quantities
File
You are a cook in a busy restaurant. You are writing a program to help you organize how much of each kind of food you need to cook. Naturally, you decide to
take a break from cooking and write a function to help. You decide that your function will take a dictionary as a parameter where the keys are the tables in the
restaurant and the values are lists of strings describing the food each table has ordered. Your function returns a dictionary with the totals for how many of each
food item you need to cook.
For example, say you have 5 tables and 3 dishes:
Tables: t1, t2, t3, t4 and t5
Dishes: Vegetarian stew, Steak pie, Poutine
Input:
You will use the table names as the keys, and use a list of the foods ordered at each table as values.
For example your dictionary may look like this:
{'t1': ['Vegetarian stew', 'Poutine', 'Vegetarian stew'],
't3': ['Steak pie', 'Poutine', 'Vegetarian stew'],
't4': ['Steak pie', 'Steak pie']}
Output:
Your function must return a dictionary with the dish as the key, and the number of times that dish was ordered as the value, Given the above input, your function
would create and return a dictionary equivalent to the following:
{'Vegetarian stew': 3, 'Poutine': 2, 'Steak pie': 3}
Here we have started the code for you. Complete it:
100%
10°C Mostly cloudy
nere to search
![Output:
File
Your function must return a dictionary with the dish as the key, and the number of times that dish was ordered as the value. Given the above input, your function
would create and return a dictionary equivalent to the following:
{'Vegetarian stew': 3, 'Poutine': 2, 'Steak pie': 3}
Here we have started the code for you. Complete it:
1 def get quantities (table_to_foods: dict[str, list[str]]) -> dict[str, int]:
**"The table to foods dict has table names as keys (e.g., 'tl', 't2', and
so on) and each value is a list of foods ordered for that table.
3.
4
Return a dictionary where each key is a food from table to foods and each
value is the quantity of that food that was ordered.
7.
>>> get quantities({'t1': ['Vegetarian stew', 'Poutine', 'Vegetarian stew'],
't3': ['Steak pie', 'Poutine', 'Vegetarian stew'],
't4': ['Steak pie', 'Steak pie']})
{'Vegetarian stew': 3, 'Poutine': 2, 'Steak pie': 3}
9.
10
1
12
13
14
food to_quantity = {}
15
16
# Accumulate the food information here.
17
18
return food_to_quantity
History
Submit
OType here to search
100%
10°C Mostly cloudy
OAC](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F10c0e332-20ab-46ed-9fce-80292c993027%2F83fe196d-b261-4421-80ac-33f19817c562%2F6rnm36m_processed.jpeg&w=3840&q=75)
Transcribed Image Text:Output:
File
Your function must return a dictionary with the dish as the key, and the number of times that dish was ordered as the value. Given the above input, your function
would create and return a dictionary equivalent to the following:
{'Vegetarian stew': 3, 'Poutine': 2, 'Steak pie': 3}
Here we have started the code for you. Complete it:
1 def get quantities (table_to_foods: dict[str, list[str]]) -> dict[str, int]:
**"The table to foods dict has table names as keys (e.g., 'tl', 't2', and
so on) and each value is a list of foods ordered for that table.
3.
4
Return a dictionary where each key is a food from table to foods and each
value is the quantity of that food that was ordered.
7.
>>> get quantities({'t1': ['Vegetarian stew', 'Poutine', 'Vegetarian stew'],
't3': ['Steak pie', 'Poutine', 'Vegetarian stew'],
't4': ['Steak pie', 'Steak pie']})
{'Vegetarian stew': 3, 'Poutine': 2, 'Steak pie': 3}
9.
10
1
12
13
14
food to_quantity = {}
15
16
# Accumulate the food information here.
17
18
return food_to_quantity
History
Submit
OType here to search
100%
10°C Mostly cloudy
OAC
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education