From 46bbd582f56f715b294cc4d44e5a53d3485999bb Mon Sep 17 00:00:00 2001 From: "exercism-solutions-syncer[bot]" <211797793+exercism-solutions-syncer[bot]@users.noreply.github.com> Date: Fri, 12 Dec 2025 05:38:25 +0000 Subject: [PATCH] [Sync Iteration] python/cater-waiter/2 --- solutions/python/cater-waiter/2/sets.py | 137 ++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 solutions/python/cater-waiter/2/sets.py diff --git a/solutions/python/cater-waiter/2/sets.py b/solutions/python/cater-waiter/2/sets.py new file mode 100644 index 0000000..5f2398e --- /dev/null +++ b/solutions/python/cater-waiter/2/sets.py @@ -0,0 +1,137 @@ +"""Functions for compiling dishes and ingredients for a catering company.""" + + +from sets_categories_data import (VEGAN, + VEGETARIAN, + KETO, + PALEO, + OMNIVORE, + ALCOHOLS, + SPECIAL_INGREDIENTS) + + +def clean_ingredients(dish_name, dish_ingredients): + """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, drink_ingredients): + """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). + + """ + + ingredients_set = set(drink_ingredients) + if ingredients_set.isdisjoint(ALCOHOLS): + return drink_name + " Mocktail" + return drink_name + " Cocktail" + + +def categorize_dish(dish_name, dish_ingredients): + """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 = ( + ("VEGAN", VEGAN), + ("VEGETARIAN", VEGETARIAN), + ("PALEO", PALEO), + ("KETO", KETO), + ("OMNIVORE", OMNIVORE), + ) + + category_found = "" + for category_name, category_set in categories: + if dish_ingredients.issubset(category_set): + category_found = category_name + break + + return dish_name + ": " +category_found + + +def tag_special_ingredients(dish): + """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`. + """ + ingredients_set = set(dish[1]) + specials = ingredients_set.intersection(SPECIAL_INGREDIENTS) + + return (dish[0],specials) + + +def compile_ingredients(dishes): + """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. + """ + + master_set = set() + for dish in dishes: + master_set |= dish + + return master_set + + +def separate_appetizers(dishes, appetizers): + """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) - set(appetizers)) + + +def singleton_ingredients(dishes, intersection): + """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. + """ + all_ingredients = compile_ingredients(dishes) + + return all_ingredients - intersection