I am trying to write a list comprehension for lines 3-6 of the function. It returns the relevant restaurant(s) depending on the choice in guests_diet. The result should be the string "Sorry, no restaurants meet your restrictions". The function works but I'm being challenged to do the list comprehension. I came up with the code below but I'm getting an incorrect result. Can anyone help?
Tried code producing incorrect results -
ans = [restaurant.append(key) for key, value in rest_names.items()\
for x in range(len(cuisine)) if cuisine[x] in value]
Code -
def no_you_pick(rest_names, cuisine):
restaurant = []
for key, value in rest_names.items():
for x in range(len(cuisine)):
if cuisine[x] in value:
restaurant.append(key)
restaurant.sort()
if len(restaurant) == 0:
return "Sorry, no restaurants meet your restrictions"
elif len(restaurant) == 1:
return ' '.join(restaurant)
return ', '.join(restaurant)
grading_scale = {"blossom": ["vegetarian", "vegan", "kosher", "gluten-free", "dairy-free"], \
"jacob's pickles": ["vegetarian", "gluten-free"], \
"sweetgreen": ["vegetarian", "vegan", "gluten-free", "kosher"]}
guests_diet = ["buttered-lobster"]
print(no_you_pick(grading_scale, guests_diet))