#__author__:Yang #date2018/6/27 menu = { '北京':{ '房山':{ '长阳':{}, '良乡':{}, '大石河':{}, }, '丰台':{ '角门': {}, '百花': {}, '华谊': {}, }, '西城':{ '金融街': { '查1': {}, '查2': {}, '查3': {}, }, 'GDC': { 'sx-1000': {}, 'sx-2000': {}, 'sx-3000': {}, }, '小西天': { '丁1': {}, '丁2': {}, '丁3': {}, }, }, }, '河北':{ '石家庄':{ '河东': { '石1': {}, '石2': {}, '石3': {}, }, '河西': { '要1': {}, '要2': {}, '要3': {}, }, '南城': { '城1': {}, '城2': {}, '城3': {}, }, }, '沧州':{ '河间': { '刘1': {}, '刘2': {}, '刘3': {}, }, '献县': { '陌南': {}, '孔庄': {}, '西城': {}, }, '肃宁': { '洗车': {}, '汔车站': {}, '火车': {}, }, }, '邢台':{ 'A1': { 'AA1': {}, 'AA2': {}, 'AA3': {}, }, 'B1': { 'BB1': {}, 'BB2': {}, 'BB3': {}, }, 'C1': { 'CC1': {}, 'CC2': {}, 'CC3': {}, }, }, }, '山东':{ }, } current_layer = menu parent_layers = [] while True: for key in current_layer: print(key) choice = input(">>>").strip() if len(choice) == 0:continue if choice in current_layer: parent_layers.append(current_layer) current_layer = current_layer[choice] elif choice == "B": if parent_layers: current_layer = parent_layers.pop() elif choice =="EXIT": break else: print("无此项")
python 用字典与列表 做三级目录
猜你喜欢
转载自www.cnblogs.com/mouni-11498/p/9239948.html
今日推荐
周排行