Advertisement
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.append(f'{k} cuisine contains {len(v)} recipes:')
- sorted_recipe = sorted(v, key=lambda y: y[0])
- for recipe, products in sorted_recipe:
- result.append(f' * {recipe} -> Ingredients: {", ".join(products)}')
- return '\n'.join(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement