优化
# -*- coding: utf-8 -*-
# @Author: oppend
# @Date: 2017-07-29 23:56:31
# @Last Modified by: oppend
# @Last Modified time: 2017-07-30 00:10:18
menu = {"北京":{"北京市":{"东城区":{4},
"西城区":{4},
"朝阳区":{4},
"丰台区":{4}
}
},
"天津":{"天津市":{"和平区":{4},
"河东区":{4},
"河西区":{4},
"南开区":{4},
"河北区":{4}
},
"经开区":{"经开西区":{4},
"经开东区":{4}
}
}
}
current_layer = menu
parrent_layer = []
while True:
for layer in current_layer:
print(layer)
choice = input('current:')
if choice in current_layer:
parrent_layer.append(current_layer)
current_layer = current_layer[choice]
elif choice == 'b':
if parrent_layer:
current_layer = parrent_layer.pop()
elif choice == 'q':
break
else:
print('不存在')