Advertisement
pacho_the_python

Untitled

Feb 17th, 2024
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 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.append(f'{k} cuisine contains {len(v)} recipes:')
  16. sorted_recipe = sorted(v, key=lambda y: y[0])
  17. for recipe, products in sorted_recipe:
  18. result.append(f' * {recipe} -> Ingredients: {", ".join(products)}')
  19.  
  20. return '\n'.join(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement