Advertisement
mbratanov

03. Cookbook

Oct 19th, 2024
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. def cookbook(*args):
  2.     all_recipes = {}
  3.     for name, cuisine, ingredients in args:
  4.         if cuisine not in all_recipes:
  5.             all_recipes[cuisine] = {}
  6.         all_recipes[cuisine][name] = ingredients
  7.  
  8.     result = ""
  9.     for cuisine, recipes in sorted(all_recipes.items(), key=lambda item: (-len(item[1]), item[0])):
  10.         result += f"{cuisine} cuisine contains {len(recipes)} recipes:\n"
  11.  
  12.         for recipe, ingredients in sorted(recipes.items()):
  13.             result += f"  * {recipe} -> Ingredients: {', '.join(ingredients)}\n"
  14.  
  15.     return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement