l = [2,3,5,10,15,16,18,22,26,30,32,35,41,42,43,55,56,66,67,69,72,76,82,83,88]
def find(l,aim,start=0,end=None):
if end == None:end = len(l)-1
if start <= end:
mid = (end - start) // 2 + start
if l[mid] > aim:
return find(l,aim,start=start,end=mid-1)
elif l[mid] < aim:
return find(l,aim,start=mid+1,end=end)
elif l[mid] == aim:
return mid
else:
return None
print('ret :',find(l,18))
# 三级菜单
menu = {
'北京': {
'海淀': {
'五道口': {
'soho': {},
'网易': {},
'google': {}
},
'中关村': {
'爱奇艺': {},
'汽车之家': {},
'youku': {},
},
'上地': {
'百度': {},
},
},
'昌平': {
'沙河': {
'老男孩': {},
'北航': {},
},
'天通苑': {},
'回龙观': {},
},
'朝阳': {},
'东城': {},
},
'上海': {
'闵行': {
"人民广场": {
'炸鸡店': {}
}
},
'闸北': {
'火车战': {
'携程': {}
}
},
'浦东': {},
},
'山东': {},
}
def menu3(menu):
while True:
for key in menu: # 北京 上海 山东
print(key)
choice = input('>>>') # 用户输入选择 北京
if choice in menu and menu[choice]:
ret = menu3(menu[choice])
if ret == 'q': return ret
elif choice == 'b' or choice == 'q':
return choice
menu3(menu)
print('回到淘宝主页')