menu = { ‘北京‘ : { ‘昌平‘ : { ‘沙河‘ : ["test1","test2"], ‘天通苑‘ : ["链家","我爱我家"], }, ‘朝阳‘ : { "望京" : ["奔驰","陌陌"], "国贸" : ["CICC","HP"], "东直门" : ["Advent","飞信"], }, ‘海淀‘ : {}, }, ‘河北‘ : {}, ‘上海‘ : {}, } exit_flag = False current_layer = menu layer = [menu] while not exit_flag: for k in current_layer: print(k) choice = input(">>>:").strip() if choice == ‘b‘: current_layer = layer[-1] layer.pop() elif choice == ‘q‘: exit() elif choice not in current_layer:continue else: layer.append(current_layer) current_layer = current_layer[choice]
原文:https://www.cnblogs.com/baixisuozai/p/11653113.html