pacho_the_python

cook_book

Feb 17th, 2024
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. def cookbook(*args):
  2. result = ''
  3. recipe_book = {}
  4. for item in args:
  5. dish = item[0]
  6. country = item[1]
  7. ingredients = item[2]
  8. if country not in recipe_book:
  9. recipe_book[country] = [(dish, ingredients)]
  10. else:
  11. recipe_book[country].append((dish, ingredients))
  12.  
  13. sorted_recipe_book = dict(sorted(recipe_book.items(), key=lambda x: (-len(x[1]))))
  14. for k, v in sorted_recipe_book.items():
  15. result += f'{k} cuisine contains {len(v)} recipes:\n'
  16. sorted_recipe = sorted(v, key=lambda y: y[0])
  17. for recipe, products in sorted_recipe:
  18. result += f' * {recipe} -> Ingredients: {", ".join(products)}\n'
  19.  
  20. return result.strip()
  21.  
  22.  
  23. # print(cookbook(
  24. # ("Spaghetti Bolognese", "Italian", ["spaghetti", "tomato sauce", "ground beef"]),
  25. # ("Margherita Pizza", "Italian", ["pizza dough", "tomato sauce", "mozzarella"]),
  26. # ("Tiramisu", "Italian", ["ladyfingers", "mascarpone", "coffee"]),
  27. # ("Croissant", "French", ["flour", "butter", "yeast"]),
  28. # ("Ratatouille", "French", ["eggplant", "zucchini", "tomatoes"])
  29. # ))
  30. print(cookbook(
  31. ("Spaghetti Bolognese", "Italian", ["spaghetti", "tomato sauce", "ground beef"]),
  32. ("Margherita Pizza", "Italian", ["pizza dough", "tomato sauce", "mozzarella"]),
  33. ("Tiramisu", "Italian", ["ladyfingers", "mascarpone", "coffee"]),
  34. ("Croissant", "French", ["flour", "butter", "yeast"]),
  35. ("Ratatouille", "French", ["eggplant", "zucchini", "tomatoes"]),
  36. ("Sushi Rolls", "Japanese", ["rice", "nori", "fish", "vegetables"]),
  37. ("Miso Soup", "Japanese", ["tofu", "seaweed", "green onions"]),
  38. ("Guacamole", "Mexican", ["avocado", "tomato", "onion", "lime"])
  39. ))
  40.  
  41. # i = {
  42. # 'Italian': [('Spaghetti Bolognese', ['spaghetti', 'tomato sauce', 'ground beef']), ('Margherita Pizza', ['pizza dough', 'tomato sauce', 'mozzarella']), ('Tiramisu', ['ladyfingers', 'mascarpone', 'coffee'])],
  43. # 'French': [('Croissant', ['flour', 'butter', 'yeast']), ('Ratatouille', ['eggplant', 'zucchini', 'tomatoes'])],
  44. # 'Japanese': [('Sushi Rolls', ['rice', 'nori', 'fish', 'vegetables']), ('Miso Soup', ['tofu', 'seaweed', 'green onions'])],
  45. # 'Mexican': [('Guacamole', ['avocado', 'tomato', 'onion', 'lime'])]
  46. #}
  47.  
Add Comment
Please, Sign In to add comment