1 l = [1,2,5,7,10,31,44,47,56,99,102,130,240]
2 def search_binary(l,item):
3 mid_index = len(l) // 2
4 if len(l) == 1:
5 if l[0] == item:
6 print('find it')
7 else:
8 print('not exists')
9 if len(l) > 1:
10 if l[mid_index] > item:
11 l = l[:mid_index]
12 search_binary(l,item)
13 elif l[mid_index] < item:
14 l = l[mid_index:]
15 search_binary(l,item)
16 else:
17 print('find it')
18 search_binary(l,32)
l = [1,2,5,7,10,31,44,47,56,99,102,130,240]
def search_binary(l,item):
mid_index = len(l) // 2
if len(l) == 1:
if l[0] == item:
print('find it')
else:
print('not exists')
if len(l) > 1:
if l[mid_index] > item:
l = l[:mid_index]
search_binary(l,item)
elif l[mid_index] < item:
l = l[mid_index:]
search_binary(l,item)
else:
print('find it')
search_binary(l,32)