l.sort()
def index(l, target_num):
if len(l) == 0:
print('没找到')
return
middle_index = len(l) // 2
if l[middle_index] < target_num:
l_right = l[middle_index + 1:]
return index(l_right, target_num)
elif l[middle_index] > target_num:
l_left = l[:middle_index]
return index(l_left, target_num)
else:
print('找到了')
index(l, 6)
标签:index,return,target,二分法,middle,num From: https://www.cnblogs.com/wellplayed/p/17706887.html