Exercise 9
Write an algorithm in python as a function which takes as a parameter a tuple (L, a) formed by a list L and an element 'a' and which returns True if the element 'a' is present in the list L and False if nope.
Solution
1 2 3 4 5 6 7 8 9 10 11 12 |
def examinList(L, a): if a in L: return True else: return False # Example L = [13, 9, 17, 23] a = 17 b = 55 print(examinList(L,a)) # The output is: True print(examinList(L,b)) # The output is: False |
Younes Derfoufi
CRMEF OUJDA
1 thought on “Solution Exercise 9: python algorithm that tests if an element is present in a list”