go6odn28

3_cook_book.py

Jun 11th, 2024
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.01 KB | None | 0 0
  1. def cookbook(*args):
  2.     ingredients_book = {}
  3.  
  4.     for elements in args:
  5.         cuisine = elements[1]
  6.         recipe_name = elements[0]
  7.         ingredients = elements[2]
  8.  
  9.         if cuisine not in ingredients_book:
  10.             ingredients_book[cuisine] = {}
  11.  
  12.         if recipe_name not in ingredients_book[cuisine]:
  13.             ingredients_book[cuisine][recipe_name] = ingredients
  14.  
  15.     result = ''
  16.     sorted_ingredients_book = dict(sorted(ingredients_book.items(), key=lambda x: (-len(x[1]), (x[0]))))
  17.  
  18.     for cuisine, recipies in sorted_ingredients_book.items():
  19.         recipies = dict(sorted(recipies.items()))
  20.         result += f"{cuisine} cuisine contains {len(recipies)} recipes:\n"
  21.         for recipie, ingredients in recipies.items():
  22.             result += f"  * {recipie} -> Ingredients: {', '.join(ingredients)}\n"
  23.  
  24.     return result
  25.  
  26.  
  27. # print(cookbook(
  28. #     ("Spaghetti Bolognese", "Italian", ["spaghetti", "tomato sauce", "ground beef"]),
  29. #     ("Margherita Pizza", "Italian", ["pizza dough", "tomato sauce", "mozzarella"]),
  30. #     ("Tiramisu", "Italian", ["ladyfingers", "mascarpone", "coffee"]),
  31. #     ("Croissant", "French", ["flour", "butter", "yeast"]),
  32. #     ("Ratatouille", "French", ["eggplant", "zucchini", "tomatoes"])
  33. # ))
  34.  
  35.  
  36.  
  37. # print(cookbook(
  38. #     ("Pad Thai", "Thai", ["rice noodles", "shrimp", "peanuts", "bean sprouts", "tamarind sauce"])
  39. #     ))
  40.  
  41.  
  42.  
  43. # print(cookbook(
  44. #     ("Spaghetti Bolognese", "Italian", ["spaghetti", "tomato sauce", "ground beef"]),
  45. #     ("Margherita Pizza", "Italian", ["pizza dough", "tomato sauce", "mozzarella"]),
  46. #     ("Tiramisu", "Italian", ["ladyfingers", "mascarpone", "coffee"]),
  47. #     ("Croissant", "French", ["flour", "butter", "yeast"]),
  48. #     ("Ratatouille", "French", ["eggplant", "zucchini", "tomatoes"]),
  49. #     ("Sushi Rolls", "Japanese", ["rice", "nori", "fish", "vegetables"]),
  50. #     ("Miso Soup", "Japanese", ["tofu", "seaweed", "green onions"]),
  51. #     ("Guacamole", "Mexican", ["avocado", "tomato", "onion", "lime"])
  52. #     ))
  53.  
  54.  
Add Comment
Please, Sign In to add comment