Dictionary and List

Joined
Apr 26, 2021
Messages
1
Reaction score
0
I am trying to write a code which takes two variables named stock and ingredients and returns the missing ingredients.
The stock part is a dictionary in pairs : ("tomato", 6)

This function will check if I have enough of every ingredient and if there isn't that item at all in the stock or just missing partially, the function will return the list of those items. If there isn't a missing one, it will return an empty list.

stock = {"apple":10, "potato":7, "banana":6, "cherry":10}
ingredients = [("banana",10), ("potato", 8), ("apple",5)]
checkStock(stock, ingredient) will return:
[("potato",1), ("banana",4)]

I am using def checkStock(stock, ingredient): but I cannot find a way of extracting the missing ingredients out of the stock. How can I do it?
 
Joined
Mar 3, 2021
Messages
240
Reaction score
30
This sounds like homework, so I'd rather guide than just give the answer. What have you tried? What, specifically, are you stuck on? Iterating a list? Getting information out of the dictionary?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,039
Messages
2,570,375
Members
47,021
Latest member
AleciaMcMa

Latest Threads

Top