Skip to content
Advertisement

count number of missing items required comparing dictionaries in python

Given a list:

JavaScript

a dictionary with ingredients I currently have:

JavaScript

and a more complex dictionary with the recipes and items per ingredients:

JavaScript

I want to output a dictionary that adds to the elements of the list list_essentials the number of items I need if I wanted to be able to make all the recipes.

The expected output I am looking for in this example is:

JavaScript

For strawberry for example I already have 1 but I need 6 to make all recipes, so the number of items I still need is 5

I tried this but the output is not correct:

JavaScript

Advertisement

Answer

i know the code is ineffecient but it works

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement