vendredi 27 mai 2016

How to search for items in a list in python

Basically I have two lists of items, and I want to check if an item from the second list is in the first list. Then if that item is in the first list, I want to assign a value to a variable, if it is not in that list, I want to assign a different value to the same variable. (As below) Can this be done?

list1 = ['dog','cat','mouse']

list2 = ['dog','tutle','bird']

if list2 in list1:
    square = 77
else:
    square = 55

print(square)

Aucun commentaire:

Enregistrer un commentaire