數據結構:數據結構
1 menu = { 2 '北京':{ 3 '海淀':{ 4 '五道口':{ 5 'soho':{}, 6 '網易':{}, 7 'google':{} 8 }, 9 '中關村':{ 10 '愛奇藝':{}, 11 '汽車之家':{}, 12 'youku':{}, 13 }, 14 '上地':{ 15 '百度':{}, 16 }, 17 }, 18 '昌平':{ 19 '沙河':{ 20 '老男孩':{}, 21 '北航':{}, 22 }, 23 '天通苑':{}, 24 '回龍觀':{}, 25 }, 26 '朝陽':{}, 27 '東城':{}, 28 }, 29 '上海':{ 30 '閔行':{ 31 "人民廣場":{ 32 '炸雞店':{} 33 } 34 }, 35 '閘北':{ 36 '火車站':{ 37 '攜程':{} 38 } 39 }, 40 '浦東':{}, 41 }, 42 '山東':{}, 43 }
需求:google
源代碼:spa
msg = { '北京':{ '海淀':{ '五道口':{ 'soho':{}, '網易':{}, 'google':{} }, '中關村':{ '愛奇藝':{}, '汽車之家':{}, 'youku':{}, }, '上地':{ '百度':{}, }, }, '昌平':{ '沙河':{ '老男孩':{}, '北航':{}, }, '天通苑':{}, '回龍觀':{}, }, '朝陽':{}, '東城':{}, }, '上海':{ '閔行':{ "人民廣場":{ '炸雞店':{} } }, '閘北':{ '火車站':{ '攜程':{} } }, '浦東':{}, }, '山東':{}, } tag=True while tag: for name1 in msg.keys(): print(name1) sheng1 = input('1請輸入省份>>:').strip() if sheng1 not in msg: print('暫無此省份,持續更新中。。。') continue while tag: for name2 in msg[sheng1]: print('%s' % (name2)) sheng2 = input('2請輸入省份>>:').strip() if sheng2 not in msg[sheng1]: print('暫無此省份,持續更新中。。。') user = input('退出菜單「Q」/返回上一層「E」\n繼續則輸入其餘任意字符>>:').strip() if user.lower() == 'q': tag = False break elif user.lower() == 'e': break else: continue while tag: for name3 in msg[sheng1][sheng2]: print('%s' % (name3)) sheng3 = input('3請輸入省份>>:').strip() if sheng3 not in msg[sheng1][sheng2]: print('暫無此省份,持續更新中。。。') user = input('退出菜單「Q」/返回上一層「E」\n繼續則輸入其餘任意字符>>:').strip() if user.lower() == 'q': tag = False break if user.lower() == 'e': break else: continue while tag: for name4 in msg[sheng1][sheng2][sheng3]: print('%s' % (name4)) sheng4 = input('4請輸入省份>>:').strip() if sheng4 not in msg[sheng1][sheng2][sheng3]: print('暫無此省份,持續更新中。。。') user = input('退出菜單「Q」/返回上一層「E」\n繼續則輸入其餘任意字符>>:').strip() if user.lower() == 'q': tag = False break if user.lower() == 'e': break else: continue while tag: for name5 in msg[sheng1][sheng2][sheng3][sheng4]: print('%s' % (name5)) user = input('退出菜單「Q」/返回上一層「E」\n繼續則輸入其餘任意字符>>:').strip() if user.lower() == 'q': tag = False break if user.lower() == 'e': break else: continue