Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def cookbook(*args):
- result = ''
- recipe_book = {}
- for item in args:
- dish = item[0]
- country = item[1]
- ingredients = item[2]
- if country not in recipe_book:
- recipe_book[country] = [(dish, ingredients)]
- else:
- recipe_book[country].append((dish, ingredients))
- sorted_recipe_book = dict(sorted(recipe_book.items(), key=lambda x: (-len(x[1]))))
- for k, v in sorted_recipe_book.items():
- result += f'{k} cuisine contains {len(v)} recipes:\n'
- sorted_recipe = sorted(v, key=lambda y: y[0])
- for recipe, products in sorted_recipe:
- result += f' * {recipe} -> Ingredients: {", ".join(products)}\n'
- return result.strip()
- # print(cookbook(
- # ("Spaghetti Bolognese", "Italian", ["spaghetti", "tomato sauce", "ground beef"]),
- # ("Margherita Pizza", "Italian", ["pizza dough", "tomato sauce", "mozzarella"]),
- # ("Tiramisu", "Italian", ["ladyfingers", "mascarpone", "coffee"]),
- # ("Croissant", "French", ["flour", "butter", "yeast"]),
- # ("Ratatouille", "French", ["eggplant", "zucchini", "tomatoes"])
- # ))
- print(cookbook(
- ("Spaghetti Bolognese", "Italian", ["spaghetti", "tomato sauce", "ground beef"]),
- ("Margherita Pizza", "Italian", ["pizza dough", "tomato sauce", "mozzarella"]),
- ("Tiramisu", "Italian", ["ladyfingers", "mascarpone", "coffee"]),
- ("Croissant", "French", ["flour", "butter", "yeast"]),
- ("Ratatouille", "French", ["eggplant", "zucchini", "tomatoes"]),
- ("Sushi Rolls", "Japanese", ["rice", "nori", "fish", "vegetables"]),
- ("Miso Soup", "Japanese", ["tofu", "seaweed", "green onions"]),
- ("Guacamole", "Mexican", ["avocado", "tomato", "onion", "lime"])
- ))
- # i = {
- # 'Italian': [('Spaghetti Bolognese', ['spaghetti', 'tomato sauce', 'ground beef']), ('Margherita Pizza', ['pizza dough', 'tomato sauce', 'mozzarella']), ('Tiramisu', ['ladyfingers', 'mascarpone', 'coffee'])],
- # 'French': [('Croissant', ['flour', 'butter', 'yeast']), ('Ratatouille', ['eggplant', 'zucchini', 'tomatoes'])],
- # 'Japanese': [('Sushi Rolls', ['rice', 'nori', 'fish', 'vegetables']), ('Miso Soup', ['tofu', 'seaweed', 'green onions'])],
- # 'Mexican': [('Guacamole', ['avocado', 'tomato', 'onion', 'lime'])]
- #}
Add Comment
Please, Sign In to add comment