From af184bfb486f3a6a5f4476beec00008351f7be35 Mon Sep 17 00:00:00 2001 From: "exercism-solutions-syncer[bot]" <211797793+exercism-solutions-syncer[bot]@users.noreply.github.com> Date: Tue, 14 Oct 2025 03:38:05 +0000 Subject: [PATCH 1/4] [Sync Iteration] python/cater-waiter/4 --- solutions/python/cater-waiter/4/sets.py | 154 ++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 solutions/python/cater-waiter/4/sets.py diff --git a/solutions/python/cater-waiter/4/sets.py b/solutions/python/cater-waiter/4/sets.py new file mode 100644 index 0000000..cc0f3e0 --- /dev/null +++ b/solutions/python/cater-waiter/4/sets.py @@ -0,0 +1,154 @@ +"""Functions for compiling dishes and ingredients for a catering company.""" +from typing import List, Set + +from sets_categories_data import ( + VEGAN, + VEGETARIAN, + KETO, + PALEO, + OMNIVORE, + ALCOHOLS, + SPECIAL_INGREDIENTS, +) + + +def clean_ingredients(dish_name: str, dish_ingredients: list) -> tuple: + """ + Remove duplicates from `dish_ingredients`. + + :param dish_name: str - containing the dish name. + :param dish_ingredients: list - dish ingredients. + :return: tuple - containing (dish_name, ingredient set). + + This function should return a `tuple` with the name of the dish as + the first item, followed by the de-duped `set` of ingredients as + the second item. + """ + + return dish_name, set(dish_ingredients) + + +def check_drinks(drink_name: str, drink_ingredients: list) -> str: + """ + Append "Cocktail" (alcohol) or "Mocktail" (no alcohol) to `drink_name`, + based on `drink_ingredients`. + + :param drink_name: str - name of the drink. + :param drink_ingredients: list - ingredients in the drink. + :return: str - drink_name appended with "Mocktail" or "Cocktail". + + The function should return the name of the drink followed by "Mocktail" + (non-alcoholic) and drink name followed by "Cocktail" (includes alcohol). + + """ + if ALCOHOLS.intersection(set(drink_ingredients)): + return f"{drink_name} Cocktail" + return f"{drink_name} Mocktail" + + +def categorize_dish(dish_name: str, dish_ingredients: set) -> str: + """ + Categorize `dish_name` based on `dish_ingredients`. + + :param dish_name: str - dish to be categorized. + :param dish_ingredients: set - ingredients for the dish. + :return: str - the dish name appended with ": ". + + This function should return a string with the `dish name: + (which meal category the dish belongs to). + `` can be any one of (VEGAN, VEGETARIAN, PALEO, KETO, or OMNIVORE). + All dishes will "fit" into one of the categories imported from `sets_categories_data.py` + """ + + categories = [ + (ALCOHOLS, "ALCOHOLS"), + (VEGETARIAN, "VEGETARIAN"), + (KETO, "KETO"), + (PALEO, "PALEO"), + (OMNIVORE, "OMNIVORE"), + (VEGAN, "VEGAN"), + (SPECIAL_INGREDIENTS, "SPECIAL_INGREDIENTS"), + ] + + result: str = "" + + for category_set, category_name in categories: + if dish_ingredients.issubset(category_set): + result = f"{dish_name}: {category_name}" + break + + return result + + +def tag_special_ingredients(dish: tuple) -> tuple: + """ + Compare `dish` ingredients to `SPECIAL_INGREDIENTS`. + + :param dish: tuple - of (dish name, list of dish ingredients). + :return: tuple - containing (dish name, dish special ingredients). + + Return the dish name followed by the `set` of ingredients that require + a special note on the dish description. For the purposes of this exercise, + all allergens or special ingredients that need to be tracked are in the + SPECIAL_INGREDIENTS constant imported from `sets_categories_data.py`. + """ + + return dish[0], SPECIAL_INGREDIENTS.intersection(set(dish[1])) + + +def compile_ingredients(dishes: list) -> set: + """ + Create a master list of ingredients. + + :param dishes: list - of dish ingredient sets. + :return: set - of ingredients compiled from `dishes`. + + This function should return a `set` of all ingredients from all listed dishes. + """ + + all_ingredients = set() + + for dish in dishes: + all_ingredients = all_ingredients.union(dish) + + return all_ingredients + + +def separate_appetizers(dishes: list, appetizers: list) -> list: + """ + Determine which `dishes` are designated `appetizers` and remove them. + + :param dishes: list - of dish names. + :param appetizers: list - of appetizer names. + :return: list - of dish names that do not appear on appetizer list. + + The function should return the list of dish names with appetizer names removed. + Either list could contain duplicates and may require de-duping. + """ + + return list(set(dishes).difference(appetizers)) + + +def singleton_ingredients(dishes: List[Set[str]], intersection) -> set: + """ + Determine which `dishes` have a singleton ingredient (an ingredient that + only appears once across dishes). + + :param dishes: list - of ingredient sets. + :param intersection: constant - can be one of `_INTERSECTIONS` + constants imported from `sets_categories_data.py`. + :return: set - containing singleton ingredients. + + Each dish is represented by a `set` of its ingredients. + + Each `_INTERSECTIONS` is an `intersection` of all dishes in the + category. `` can be any one of: + (VEGAN, VEGETARIAN, PALEO, KETO, or OMNIVORE). + + The function should return a `set` of ingredients that only appear in a single dish. + """ + + singletons: set = set() + for dish in dishes: + singletons = singletons.union(dish.difference(intersection)) + return singletons From 9212d2abfeb5bc4d7428d0e9fa9518ffd97d2578 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Mon, 13 Oct 2025 20:49:11 -0700 Subject: [PATCH 2/4] Update sets.py --- cater-waiter/sets.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/cater-waiter/sets.py b/cater-waiter/sets.py index cc0f3e0..0b9e951 100644 --- a/cater-waiter/sets.py +++ b/cater-waiter/sets.py @@ -56,8 +56,10 @@ def categorize_dish(dish_name: str, dish_ingredients: set) -> str: This function should return a string with the `dish name: (which meal category the dish belongs to). - `` can be any one of (VEGAN, VEGETARIAN, PALEO, KETO, or OMNIVORE). - All dishes will "fit" into one of the categories imported from `sets_categories_data.py` + `` can be any one of (VEGAN, VEGETARIAN, PALEO, KETO, + or OMNIVORE). + All dishes will "fit" into one of the categories imported from + `sets_categories_data.py` """ categories = [ @@ -103,7 +105,8 @@ def compile_ingredients(dishes: list) -> set: :param dishes: list - of dish ingredient sets. :return: set - of ingredients compiled from `dishes`. - This function should return a `set` of all ingredients from all listed dishes. + This function should return a `set` of all ingredients from + all listed dishes. """ all_ingredients = set() @@ -122,8 +125,8 @@ def separate_appetizers(dishes: list, appetizers: list) -> list: :param appetizers: list - of appetizer names. :return: list - of dish names that do not appear on appetizer list. - The function should return the list of dish names with appetizer names removed. - Either list could contain duplicates and may require de-duping. + The function should return the list of dish names with appetizer names + removed. Either list could contain duplicates and may require de-duping. """ return list(set(dishes).difference(appetizers)) @@ -145,7 +148,8 @@ def singleton_ingredients(dishes: List[Set[str]], intersection) -> set: category. `` can be any one of: (VEGAN, VEGETARIAN, PALEO, KETO, or OMNIVORE). - The function should return a `set` of ingredients that only appear in a single dish. + The function should return a `set` of ingredients that only appear in a + single dish. """ singletons: set = set() From b272687b38b84240e82eb742a366e1afe0dc88e6 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Mon, 13 Oct 2025 20:49:23 -0700 Subject: [PATCH 3/4] Update sets_test.py --- cater-waiter/sets_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cater-waiter/sets_test.py b/cater-waiter/sets_test.py index d36de6a..17d7a2d 100644 --- a/cater-waiter/sets_test.py +++ b/cater-waiter/sets_test.py @@ -1,4 +1,4 @@ -# pylint: disable=C0301, C0114, C0115, C0116, R0904 +# pylint: disable=C0301, C0114, C0115, C0116, R0904, W0611 import unittest import pytest From f06b0df45c9524f0ace785ce3d822732913f2555 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Mon, 13 Oct 2025 20:49:37 -0700 Subject: [PATCH 4/4] Update sets.py --- cater-waiter/sets.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cater-waiter/sets.py b/cater-waiter/sets.py index 0b9e951..ed5e636 100644 --- a/cater-waiter/sets.py +++ b/cater-waiter/sets.py @@ -1,4 +1,5 @@ """Functions for compiling dishes and ingredients for a catering company.""" + from typing import List, Set from sets_categories_data import (