1
N
def find_item(list, item):
#Returns True if the item is in the list, False if not.
if len(list) = 0 :
return False
==
3
4
5
6
7
#Is the item in the center of the list?
middle = len(list)//2
if list[middle] == item:
return True
8
9
10
11
12
13
14
15
16
17
18
19
#Is the item in the first half of the list?
if item < list[middle]:
#Call the function with the first half of the list
return find_item(list[:middle], item)
else:
#Call the function with the second half of the list
return find_item(list[middle+1:], item)
return false
20
21
#Do not edit below this line - This code helps check your work!
list_of_names = ["Parker", "Drew", "Cameron", "Logan", "Alex", "Chris", "Terry", "Jamie", "
22
23​

Respuesta :

def find_item(list, item):

   return True if item in list else False

list_of_names = ["Parker", "Drew", "Cameron", "Logan", "Alex", "Chris", "Terry", "Jamie"]

print(find_item(list_of_names, "Drew"))

This is all you need to check if any element is inside your list. In our find_item function we return true if the item is in the list and false if it is not in the list.

Our print function calls our find_item function and checks our list of names for the element "Drew" and since drew is in the list of names, True is printed to the console.