I have to write a function that takes three dishes and an ingredient and outputs true if the ingredient isn’t in the dish and false if any of the dishes contain the ingredient.
I’ve been trying this for hours and initially was having an issue where it was either outputting true or false for all test cases regardless. I have now tried using any() but its returning a TypeError: ‘bool’ object is not iterable and I’m getting really confused and frustrated.
any advice would be much appreciated.
def free_from(menu: list, ingredient: str):
"""Return whether ingredient is in dish.
Preconditions: menu = dish1, dish2, dish3
Postconditions: if menu has ingredient = false else true
"""
for dish in menu:
if any(ingredient in menu):
return False
return True
menu = [
['soup','onion','potato','leek','celery'],
['pizza','bread','tomato','cheese','cheese'],
['banana']
]
>Solution :
for dish in menu:
if ingredient in dish:
return False
return True