Due: 10:00pm EST on Monday, November 9, 2026.
Instructions: complete this homework using Thonny, because this requires working with external files (and that can be cumbersome in Colab).
Starter code: Click here to download the WellesleyFresh folder to get started. This folder contains the one text file (wellesleyFreshData.py) that you need to use to load the list of dictionaries. Inside the WellesleyFresh folder, create a new file called username_wellesleyFresh.py. For example, this is how Saoirse Ronan would name her file: sr112_hw8_wellesleyFresh.py. Write all your code for this assignment, including your testing code, in this file.
Practice accessing dictionary values using keys
Loop through a list of dictionaries
Practice sorting data
In this task, you are provided with a list of dictionaries, where each dictionary represents a meal served at a Wellesley dining hall. The file wellesleyFreshData.py defines a variable dishes. If you add the line below to your own username_wellesleyFresh.py file:
from wellesleyFreshData import dishes
this will allow to access the dishes variable.
The dishes variable stores a list of dictionaries for a week’s worth of meals on campus. Our data is from about 10 years ago, when Pomeroy had a vegetarian dining hall. Each dictionary has the following keys: dish, meal, hall, and day. Let’s take a look at a couple of the dictionaries in the dishes list:
{'dish': 'Macaroni Cheese',
'meal': 'Homestyle Dinner',
'hall': 'Bae Pao Lu Chow',
'day': 'Monday'},
{'hall': 'Pomeroy',
'day': 'Wednesday',
'meal': 'Dinner',
'dish': 'Lemon Eggplant Risotto'},
You will write five functions, described below, to analyze the Wellesley Fresh data.
To get started, make sure you have downloaded the WellesleyFresh folder by clicking on the link in the Starter Code section above. This will give you access to the list of dictionaries stored in the dishes variable.
Takes three parameters:
a list of dictionaries of Wellesley Fresh menu entries,
a string that is the day of the week (eg "Monday"),
a string that is the dining hall (eg "Tower"). Prints out a line of the form meal:dish for each entry for the specified dining hall available on the specified day (you can use f-strings). The order of the lines is unimportant.
>>> getMenu(dishes, 'Monday', 'Pomeroy')
Breakfast:Waffle Bar
Pasta Bar:Tossed In Penne
Breakfast:Red Bliss Home Fries
Lunch:Vegan Meatball Calzone
Breakfast:Assorted Pastry
Lunch:Black Bean Burger
Breakfast:Egg Whites Upon Request
Pasta Bar:Roasted Butternut Squash
Dinner:Sweet Potatoes Cakes
Breakfast:Oatmeal Bar
Deli:Caprese Salad
Dinner:Asparagus Risotto
Breakfast:Hard Boiled Eggs
Breakfast:Cottage Cheese
Lunch:Roasted Corn
Breakfast:Maple Glazed Tofu
Deli:Bean Curd with Chili Sauce
Dinner:Green Beans
Breakfast:Fried Egg Sandwich
Deli:Tabbouleh
Breakfast:Fresh Fruit
Deli:Hummus
Dinner:Tuscan White Beans
Breakfast:Yogurts
Lunch:Fresh French Fries
Breakfast:Scrambled Eggs
Soup of the Day:Pumpkin Soup
Lunch:Brown Rice
Deli:Cheese of the Day
Dinner:Herbed Tofu
>>> getMenu(dishes, 'Sunday', 'Bae Pao Lu Chow')
Continental Breakfast:Fresh Fruit
Fusion Lunch:Home Fries
Continental Breakfast:Yogurt Cottage Cheese
Grill:Lunch Omelets
Homestyle Dinner:Garlic Chicken
Homestyle Dinner:Barley Pilaf
Continental Breakfast:Hard Boiled Eggs
Fusion Lunch:Pierogies
Deli MYO:Sliced Ham
Continental Breakfast:Pastries
Pizza:Scones Cookies
Pizza:Cheese Pizza
Continental Breakfast:Waffle Bar
Homestyle Dinner:Lima Beans
Pizza:Pepperoni Pizza
Homestyle Dinner:Tempeh Chili
Grill:Tater Triangles
Fusion Lunch:Scrambled Eggs
Continental Breakfast:Oatmeal Bar
Deli MYO:Sliced Turkey
Soup:Pumpkin Soup
Grill:Falafel Hummus
Fusion Lunch:Bacon
This function builds and returns a dictionary of dish word frequencies, given the Wellesley Fresh list of dictionaries (stored in the dishes variable). This function should return a dictionary with 541 key:value pairs.
Here are some sample key:word pairs in the dictionary that makeDishWordFreqDict returns:
waffle 33
ham 25
macaroni 3
ginger 2
bar 50
cabbage 3
cheese 63
sandwich 5
Let's say you test your function like this:
wordFreqDict = makeDishWordFreqDict(dishes)
Then, you can check your results against the table above, for example,
wordFreqDict['waffle'] should return 33
wordFreqDict['macaroni'] should return 3
Takes two parameters:
a list of dictionaries of Wellesley Fresh menu entries, and
an integer indicating the minimum number of times a word must appear in the week's dish descriptions for the function to print it.
The function prints out in alphabetical order all (lowercased) words that appear at least the specified number of times anywhere in the "dish" descriptions for the week (use sorted here). The number of occurrences of each of these words is also printed alongside the word (you can use f-strings here). This function must call makeDishWordFreqDict. The function only prints; it does not return a value.
>>> printDishWords(dishes, 50)
bar 50
cheese 63
eggs 63
v 67
>>> printDishWords(dishes, 35)
bar 50
cheese 63
chicken 45
egg 35
eggs 63
salad 36
turkey 37
v 67
veg 48
>>> printDishWords(dishes, 20)
bar 50
bean 20
beans 20
beef 26
boiled 24
cheese 63
chicken 45
egg 35
eggs 63
fresh 28
fruit 23
ham 25
hard 24
marinara 20
oatmeal 26
potatoes 24
rice 33
roasted 25
salad 36
sauce 26
scrambled 34
sliced 24
turkey 37
v 67
veg 48
waffle 33
whites 24
This function takes two parameters:
the list of dictionaries of Wellesley Fresh menu entries, and
a string search term and prints all entries that match the given search term, case insensitive. A term matches an entry if it is a substring of any of its dictionary values. Entries are printed out in sorted order with colon-separated hall, meal, dish, and day values. The searchTerm can match ANY value in the dictionary, it is not limited to food items.
searchMenu HINTS
Write a helper predicate that returns True if the given search term occurs as a substring in any of the values for a given dictionary, and returns False otherwise.
For example, let’s call the predicate isWordInDict (you can name yours anything you like) and let’s say the search term is "cream" and this is one dictionary:
food = {102: 'cookies and cream', 'banana': 12, 'major': 'CS'}
Then,
isWordInDict('cream',food) returns True
Because 'cream' is a substring of the key 102 in the food dictionary
isWordInDict('pudding',food) returns False
Because 'pudding' is not a substring of any value in the food dictionary.
isWordInDict('banana',food) returns False
Because 'banana' is not a substring of any value in the food dictionary. banana' is a key, but the isWordInDict predicate only looks at values.
>>> searchMenu(dishes, 'noodles')
Bae Pao Lu Chow:Pure:Zucchini Noodles with:Monday
Bates:Pasta:Egg Noodles Thai Peanut:Friday
Bates:Pasta:Lo Mein Noodles:Tuesday
Pomeroy:Pasta Bar:Warm Glass Noodles And:Wednesday
Stone Davis:Lunch:Egg Noodles:Thursday
Tower:Homestyle Lunch:Egg Noodles:Monday
>>> searchMenu(dishes, 'peanut')
Bae Pao Lu Chow:Deli:Peanut Butter Jelly:Friday
Bates:Pasta:Egg Noodles Thai Peanut:Friday
>>> searchMenu(dishes,'Bates')
Bates:Breakfast:Hardboiled Eggs Veg:Friday
Bates:Breakfast:Hardboiled Eggs Veg:Monday
Bates:Breakfast:Hardboiled Eggs Veg:Thursday
Bates:Breakfast:Hardboiled Eggs Veg:Tuesday
Bates:Breakfast:Hardboiled Eggs Veg:Wednesday
...
[note: about 150 printed lines not shown here to
save space here]
>>> searchMenu(dishes, 'lem')
Pomeroy:Dinner:Lemon Eggplant Risotto:Wednesday
Stone Davis:Dinner:Lemon Spinach:Monday
Tower:Fusions:Lemons:Wednesday
Tower:Vegan Grain Bar:Lemon Oregano Chickpeas:Monday
>>> searchMenu(dishes, 'berry')
Pomeroy:Dinner:Cranberry Sauce:Friday
Stone Davis:MYO Deli:Cranberry Sauce:Thursday
Tower:Vegan Grain Bar:Cranberry BBQ Tofu:Sunday
Tower:Vegan Grain Bar:Wheat Berry Salad:Monday
>>> searchMenu(allEntries, 'garlic')
Bae Pao Lu Chow:Homestyle Dinner:Garlic Chicken:Sunday
Bae Pao Lu Chow:Homestyle Dinner:Garlic Crescent:Wednesday
Bates:Brunch Homestyle:Garlic Toast:Sunday
Bates:Homestyle Lunch:Garlic Bread Sticks:Friday
Bates:Homestyle Lunch:Garlic Toast:Thursday
Bates:Homestyle Lunch:Squash Garlic Pizza:Monday
Pomeroy:Dinner:Garlic Bread:Sunday
Pomeroy:Dinner:Garlic Bread:Tuesday
Pomeroy:Lunch:Garlic Bread:Thursday
Pomeroy:Pasta Bar:Spaghetti Squash with Garlic:Tuesday
Stone Davis:Dinner:Garlic Bread:Wednesday
Stone Davis:Pasta:Garlic Butter:Wednesday
Stone Davis:Pizza:Spinach Garlic:Friday
Tower:Fusions:Garlic Bread:Monday
Tower:Homestyle Dinner:Garlic Bread Veg:Saturday
Tower:Homestyle Lunch:Garlic Bread Veg:Tuesday
Tower:Pasta:Garlic Butter Sauce Veg:Saturday
Tower:Pizza Pasta:Cheese Pepperoni Mushgarlic:Monday
Tower:Pizza Pasta:Garlic Butter Sauce:Tuesday
Tower:Soup:Garlicky Lentil Soup:Monday
Tower:Soup:Mushroom Celery Garlic Soup:Wednesday
Tower:Vegan Grain Bar:Garlicky White Beans:Tuesday
This function takes the list of meal dictionaries, and returns a nested dictionary where:
the main keys are meal names
each meal maps to another dictionary
the inner dictionary’s keys are dining halls
each dining hall maps to a list of dishes
The 'day' field should NOT appear in the final structure. In other words, here is the required structure of the returned dictionary:
{
meal: {
hall: [dish1, dish2, dish3]
}
}
makeMealDictionary requirements:
Do not hardcode meal names or dining halls.
For any meal, for any dining hall, there should be no duplicates in the list of dishes.
Your function must work for the full dataset.
Use dictionaries and lists only.
The function does not print; it returns the new dictionary.
Here's a testing function that you may use, if you like, to test makeMealDictionary
def testMealDict(mealDict,meal):
'''Extracts the values associated with the key meal in the mealDict
and prints each dining hall and the number of entries served at that dining hall,
and then for each dining hall, the meals that are served at the dining hall that
fall under that given meal key. For example, testMealDict(mealDict, 'Continental Breakfast')
prints the following:
--------------------
**CONTINENTAL BREAKFAST**
Bae Pao Lu Chow 6
Waffle Bar
Fresh Fruit
Oatmeal Bar
Yogurt Cottage Cheese
Hard Boiled Eggs
Pastries
Bates 4
Steel Cut Oatmeal
Scrambled Eggs Or Whites Veg
Waffle Station Veg
Hardboiled Eggs Veg
Pomeroy 9
Oatmeal Bar
Assorted Breakfast Pastry
Cottage Cheese
Fresh Fruit
Yogurts
Sweet Potato Barrels
Hard Boiled Eggs
Belgian Waffle Bar
Yukon Potatoes
Tower 5
Hardboiled Eggs
Fresh Sliced Fruit V
Assorted Breakfast Pastry Veg
Steel Cut Oatmeal V
Waffle Bar V
'''
data = mealDict[meal]
print('-'*20)
print('**' + meal.upper() + '**')
for item in data:
print(' ',item, len(data[item]))
for flavor in data[item]:
print(' ',flavor)
>>> mealDict = makeMealDictionary(dishes)
>>> testMealDict('Breakfast')
--------------------
**BREAKFAST**
Bates 4
Scrambled Eggs Or Whites Veg
Steel Cut Oatmeal
Hardboiled Eggs Veg
Waffle Station Veg
Pomeroy 22
Waffle Bar
Yogurts
Scrambled Eggs
Red Bliss Home Fries
Curried Tofu Scramble
Oatmeal Bar
Maple Glazed Seitan
Breakfast Sausage Patties
Assorted Pastry
Hard Boiled Eggs
Cottage Cheese
Leek Mushroom Quiche
Egg Whites Upon Request
Yukon Potatoes
Maple Glazed Tofu
Chocolate Chip Pancakes
Lyonnais Potatoes
Buttermilk Pancakes
Fried Egg Sandwich
Fresh Fruit
Potato Barrels
Veggie Bacon
Stone Davis 24
Hard Boiled Eggs
Scrambled Eggs
Fried Egg Sandwich
Egg Cheese Croissant
Egg Whites to Order
Waffle Bar
Country Sliced Potatoes Veg
Turkey Sausage Links
Steel Cut Oats Bar V
Poached Eggs
Classic French Toast
Cheese Omelets
Sweet Potato Tots
Hollandaise
Buttermilk Pancakes
Tater Tots
Hash Browns
Pork Bacon
Pork Sausage Patty
Egg Cheese on English Muffin Veg
Egg Cheese on Bagel Veg
Bacon Egg Cheese Biscuit Veg
Crunchy French Toast
Pit Ham
Tower 24
Steel Cut Oatmeal V
Red Bliss Home Fries V
Egg Cheese Bagel
Egg Cheese Croissant
Waffle Bar V
Scrambled Eggs to Order
Turkey Sausage Links
Turkey Bacon
Fresh Sliced Fruit V
Scrambled Egg Whites to Order
Hard Boiled Eggs
Cheese Omelets
Cream of Wheat V
Grits V
Turkey Sausage Patties
Brsug Cinn Pumpkin Pancakes
Egg Cheese Muffin
French Toast
Seasoned Sliced Potatoes V
Scrambled Eggs
Ham Swiss Omelet
Pork Bacon
Shredded Hashbrowns V
Corned Beef Hash
>>> testMealDict('Lunch')
--------------------
**LUNCH**
Pomeroy 24
Refried Beans
Socca
Black Bean Corn
Herbed White Beans
Beef Stew
Honey Glazed Carrots
Fresh Chips
Vegan Meatball Calzone
Black Bean Burger
South West Rice
Garlic Bread
Nacho Chip Salsa
Tuna Casserole
California Blend
Roasted Corn
Tamale
Yellow Rice
Roasted Winter Vegetable
Grilled Caprese Sandwich
Lima Beans
Fresh French Fries
Brown Rice
Vegetable Chicken
Spaghetti Meat Sauce
Stone Davis 25
Broccoli
Biscuits
Edamame
Spanish Rice
Rolls
Herb Butter Ravioli
Egg Noodles
Corn Bread
Black Bean Stew
Brussel Sprouts
Swiss Chard
Corn
Roasted Potatoes
Sticky Rice
German Bratwurst
BBQ Pork Butt Roti
Turnips
Creamed Spinach
Tamale Pie
Italian Pot Roast
Miso Glazed Salmon
Carrots
Veggie Lo Mien
Cider Cooked Cabbage
Acorn Squash
>>> testMealDict('Pizza')
--------------------
**PIZZA**
Bae Pao Lu Chow 15
Squash
Arugula Shaved Parm
Cheese Pizza
Creamed Spinach
Thai Shrimp
Chef's Daily Artisan
Roasted Veg Pesto
Scrod with Olives Peppers Onions
Bbq Beef Pizza
Bacon Turkey Cheddar
Scones Cookies
Pepperoni Pizza
Chicken Parm Pizza
Apple Pizza
White Pizza
Stone Davis 12
White
Spinach Garlic
Pork Tontasku
Cheese
Pepperoni
Apple Pie
Supreme
Pierogi
Buffalo Chicken
Cheese Steak
Sausage
Vegan Veg
Tower 1
Closed
>>> testMealDict('Soup')
--------------------
**SOUP**
Bae Pao Lu Chow 8
Ham Cabbage
Creamy Onion Leek Potage
Ginger Soup
Beef Rice
Chicken Barley
New England Clam
Butternut Squash
Pumpkin Soup
Stone Davis 10
Black Bean Soup
Pumpkin Bisque
Tomato
Tomato Chickpea
Lentil
Pasta Fagioli
Italian Wedding
Split Pea
Chicken Noodle
Manhattan Clam
Tower 12
Garlicky Lentil Soup
Roast Chicken Apple Soup
N E Clam Chowder
Pasta Fagiole Veg
Black Bean Soup V
Cream of Red Pepper Soup
Beef Chili
Chicken Rice Soup
Curried Chicken Soup
Pumpkin Bisque
Mushroom Celery Garlic Soup
Cream of Tomato Soup V
Make sure that your file:
Starts with a comment indicating your name, the date, and any collaborators
Save your python file as username_wellesleyFresh.py, e.g, this is how Saoirse Ronan would name her file: sr112_hw8_wellesleyFresh.py
Each function has a docstring
Each function is tested properly
Your code works correctly without crashing and does not generate any errors
Submit your python file in gradescope