I want to make a function that takes a list of strings and a dictionary as inputs. If any strings in the list match a set of values in the dictionary, they should return a key corresponding to those values.
An example input would look something like available_dishes(ingredients, recipes). Where
ingredients = ['Fish','Rice','Eggs','Ketchup']
recipes = {'Sushi':['Fish','Rice','Seaweed'],'Grilled_Fish':['Fish'],'Omurice':['Eggs','Rice','Ketchup']}
Because the list only has the necessary ingredients for grilled fish and omurice, this would return the output: ['Grilled_Fish','Omurice']. Specifically, the results should appear in the order that the keys appear in the dictionary.
What I'm Trying
In my attempt, I have isolated one of the lists in the list of dictionary values. I tried focusing on one list so that I might understand how the rest of them might function. What I’ve made isn’t necessarily a function but a group of variables I wanted to try interpreting.
recipe_ingredients = list(recipes.values())
for i in ingredients:
if i in recipe_ingredients[0]:
print(i)
Unfortunately, for now, my knowledge of python is limited so this only returns the matching ingredients between the two lists: Fish Rice. I’m still somewhat inexperienced with for loops, so I’d like to see how this could be done using them as well as if statements. If possible, could this be done without the use of list comprehension?