参考:https://blog.csdn.net/weixin_42444693/article/details/104196222
https://cloud.tencent.com/developer/article/1794163
l = [1, 3, 2, 7, 10, 8, 9, 4]
# 运用递归来进行二分法查找
def dichotomy(l, num):
if len(l) == 0:
print("it's not in the list")
return False
l.sort()
print(l)
mid_index = len(l) // 2
if num > l[mid_index]:
dichotomy(l[mid_index + 1:], num)
elif num < l[mid_index]:
dichotomy(l[0:mid_index], num)
else:
print("it's on the list")
dichotomy(l, 2)