mardi 24 novembre 2015

Python Comprehensions troubleshooting [duplicate]

This question already has an answer here:

I have problems to set up correctly my if statement.

This is my code:

def task_13():
    Main_meal=['Meat','Cheese','Fish']
    addons=['Potatoes','Rice','Salad']
    my_meal=[(x+y) for x in Main_meal for y in addons if (x+y)!= 'FishRice' and 'CheeseRice']
    print(my_meal)

My question is why Python filter out the 'CheeseRice' when is it stated there but only filter out the 'FishRice' option.

This is my output:

['MeatPotatoes', 'MeatRice', 'MeatSalad', 'CheesePotatoes', 'CheeseRice', 'CheeseSalad', 'FishPotatoes', 'FishSalad']

Thank you for your advice.

Aucun commentaire:

Enregistrer un commentaire