-3

Suppose a_list = [1,2,3,4,5] and a_integer = 5

How do I make a function match(a_list, a_integer) such that it returns True when a_integer is in a_list and False if a_integer is not in a_list using two recursive calls?

I tried this...but it didnt return anything. Apologies I just learnt recursion

def match(a_list, a_int):
'''Using two recursive calls'''
if len(a_list) == 1 and a_list[0] != a_int:
    return False
elif len(a_list) == 1 and a_list[0] == a_int:
    print(a_list)
    return True

mid = len(a_list) // 2
left = match(a_list[:mid], a_int)
right = match(a_list[mid:], a_int)

0 Answers0