Question
Implement a function 'ingredients' that takes a recipe and returns a dictionary of the ingredients needed. Details: accepts one multiline str argument containing a recipe
Implement a function 'ingredients' that takes a recipe and returns a dictionary of the ingredients needed. Details:
- accepts one multiline str argument containing a recipe
- each line of the recipe is either an instruction line or an ingredient line. The ingredient lines contain the character ':' , the instruction lines do not.
- instruction lines should be ignored
- ingredient lines will be structured like 'active dry yeast: 10g' . This breaks down as: an ingredient, e.g., 'active dry yeast' (can be multiple words) the character ':' followed by a space the quantity, e.g., '10g' , which will always be an integer (number of digits can vary) followed always by the letter 'g' ( for grams)
- note that a particular ingredient may appear on more than one line, see sourdoughStarter below
The function ingredients should output a dictionary:
- keys are ingredients
- each value is an int specifying the number grams of that ingredient used in the recipe
- if an ingredient appears on more than one line, the value should be the total amount of the ingredient required
---------------------------------------------------------------------------------------------------------------
Sample usage:
>>> ganache='semi-sweet chocolate: 224g heavy cream: 224g Chop chocolate, place in a bowl. Heat cream until it simmers. Add cream to bowl, let stand for 3 minutes, then whisk until smooth.'
>>> print(ganache)
semi-sweet chocolate: 224g
heavy cream: 224g
Chop chocolate, place in a bowl. Heat cream until it simmers.
Add cream to bowl, let stand for 3 minutes, then whisk until smooth.
>>> ingredients(ganache)
{'semi-sweet chocolate': 224, 'heavy cream': 224}
>>> ingredients(ganache)['heavy cream']
224
>>> sourdoughStarter= 'Mix flour: 113g water: 113g Cover loosely and let sit for 24 hours. Discard 1/2 of the starter and add flour: 113g water: 113g Mix and let sit for 24 hours. Discard 1/2 of the starter and add flour: 113g water: 113g Mix and let sit for 24 hours. Repeat a bunch of times ...'
>>> ingredients(sourdoughStarter) # flour and water listed multiple times
{'flour': 339, 'water': 339}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started