#python之三级目录低配版

menu = {
'北京':{
'朝阳':{
'国贸':{
'CICC':{ },
'HP':{ },
'渣打银行':{ },
'CCTV':{ },
},
'望京':{
'陌陌':{ },
'奔驰':{ },
'':{ },
},
'三里屯':{
'优衣库':{ },
'apple':{ },
},
},
'昌平':{
'沙河':{
'老男孩':{ },
'阿泰包子':{ },
},
'天通苑':{
'链家':{ },
'我爱我家':{ },
},
'回龙观':{ },
},
'海淀':{
'五道口':{
'谷歌':{ },
'网易':{ },
'搜狐':{ },
'sogo':{ },
'快手':{ },
},
'中关村':{
'youku':{ },
'iqiyi':{ },
'汽车之家':{ },
'新东方':{ },
'QQ':{ },
}
},
},
'上海':{
'浦东':{
'陆家嘴':{
'CICC':{ },
'高盛':{ },
'摩根':{ },
},
'外滩':{ }, },
'闵行':{ },
'静安':{ },
},
'山东':{
'济南':{ },
'德州':{
'乐陵':{
'丁坞镇':{ },
'城区':{ },
},
'平原':{ },
},
'青岛':{ },
},
} back_flag=False
exit_flag=False
while not back_flag and not exit_flag:
for key in menu:
print(key)
choice=input("1>>:").strip()
if choice=="q":
exit_flag=True
if choice in menu:
while not back_flag and not exit_flag:
for key2 in menu[choice]:
print(key2)
choice2=input("2>>:").strip()
if choice2 =='q':
exit_flag=True
if choice2 =='b':
back_flag=True
if choice2 in menu[choice]:
while not back_flag and not exit_flag:
for key3 in menu[choice][choice2]:
print(key3)
choice3=input("3>>:").strip()
if choice3=='q':
exit_flag=True
if choice3=='b':
back_flag=True
if choice3 in menu[choice][choice2]:
while not back_flag and not exit_flag:
for key4 in menu[choice][choice2][choice3]:
print(key4)
choice4=input("4>>:").strip()
print('last level')
if choice4=='q':
exit_flag=True
if choice4=='b':
back_flag=True
else:
back_flag=False
else:
back_flag=False
else:
back_flag=False
#python之三级目录高级版
menu = {
'北京':{
'朝阳':{
'国贸':{
'CICC':{ },
'HP':{ },
'渣打银行':{ },
'CCTV':{ }
},
'望京':{
'陌陌':{ },
'奔驰':{ },
'':{ }
},
'三里屯':{
'优衣库':{ },
'apple':{ }
}
},
'昌平':{
'沙河':{
'老男孩':{ },
'阿泰包子':{ }
},
'天通苑':{
'链家':{ },
'我爱我家':{ }
},
'回龙观':{ },
},
'海淀':{
'五道口':{
'谷歌':{ },
'网易':{ },
'搜狐':{ },
'sogo':{ },
'快手':{ }
},
'中关村':{
'youku':{ },
'iqiyi':{ },
'汽车之家':{ },
'新东方':{ },
'QQ':{ }
}
}
},
'上海':{
'浦东':{
'陆家嘴':{
'CICC':{ },
'高盛':{ },
'摩根':{ }
},
'外滩':{ } },
'闵行':{ },
'静安':{ }
},
'山东':{
'济南':{ },
'德州':{
'乐陵':{
'丁坞镇':{ },
'城区':{ }
},
'平原':{ }
},
'青岛':{ }
}
}
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_layer=current_layer #改之前相当于护父亲
parent_layers.append(current_layer)
current_layer=current_layer[choice] #改成子层
elif choice == "b":
if parent_layers:
current_layer=parent_layers.pop()#弹出列表最后一个元素,并返回该元素的值
else:
print("无此项")

python之三级目录的更多相关文章

  1. python编辑三级目录

    一.需求分析 三级目录要能够实现以下要求: 显示根目录,任何子目录中都可以通过输入b字符来返回根目录 任何子目录中都可以通过输入q字符来返回上一级目录 主目录进入子目录后,系统能够打印子目录,根据指打 ...

  2. 用python选择及显示三级目录,可返回上层目录以及随时跳出。

    # -*- coding: utf-8 -*-"""Created on Fri Jul 29 09:43:38 2016 @author: yinggang" ...

  3. python学习笔记目录

    人生苦短,我学python学习笔记目录: week1 python入门week2 python基础week3 python进阶week4 python模块week5 python高阶week6 数据结 ...

  4. python打怪之路【第三篇】:利用Python实现三级菜单

    程序: 利用Python实现三级菜单 要求: 打印省.市.县三级菜单 可返回上一级 可随时退出程序 coding: menu = { '北京':{ '朝阳':{ '国贸':{ 'CICC':{}, ' ...

  5. python遍历一个目录,输出所有文件名

    python遍历一个目录,输出所有文件名 python os模块 os import os  def GetFileList(dir, fileList):  newDir = dir  if os. ...

  6. python之工作目录和文件引用

    1.参考 如何获得Python脚本所在目录的位置 Python 相对导入与绝对导入 还没细看 2.不考虑exe打包 sys.path[0] #顶层运行脚本的绝对目录 os.path.split(os. ...

  7. Python数据分析学习目录

    python数据分析学习目录 Anaconda的安装和更新 矩阵NumPy pandas数据表 matplotlib-2D绘图库学习目录                      

  8. 【转】python文件和目录操作方法大全(含实例)

    python文件和目录操作方法大全(含实例) 这篇文章主要介绍了python文件和目录的操作方法,简明总结了文件和目录操作中常用的模块.方法,并列举了一个综合实例,需要的朋友可以参考下一.python ...

  9. python获取指定目录下所有文件名os.walk和os.listdir

    python获取指定目录下所有文件名os.walk和os.listdir 觉得有用的话,欢迎一起讨论相互学习~Follow Me os.walk 返回指定路径下所有文件和子文件夹中所有文件列表 其中文 ...

随机推荐

  1. fail to resolve com.umeng.analytics:analytics:latest.integration

    今天友盟接入的时候,他娘的居然提示我这个友盟jar包拉不下来 明明之前还好好的,而且别的什么东西都没问题,就这个有问题 原来使用的是 compile "com.umeng.analytics ...

  2. Underscore源码阅读极简版入门

    看了网上的一些资料,发现大家都写得太复杂,让新手难以入门.于是写了这个极简版的Underscore源码阅读. 源码: https://github.com/hanzichi/underscore-an ...

  3. mac系统vscode环境配置,以及iTerm2配置Zsh + on-my-zsh shell

    https://segmentfault.com/a/1190000013612471?utm_source=tag-newest https://ohmyz.sh/ 一:安装iTerm2终端 htt ...

  4. List Except 失效 差集失效

    https://www.cnblogs.com/benhua/p/6805192.html

  5. Delphi indy线程控件TIdThreadComponent的使用

    当程序需要做耗时操作,例如访问数据库获取较多的数据.获取大文件MD5.网络访问数据量比较大.界面需要频繁刷新等等,都可以用线程来解决界面卡顿的问题,从而优化用户体验. 在知道TIdThreadComp ...

  6. bzoj1688

    题解: 暴力枚举生哪一些病 然后判断一下即可 代码: #include<bits/stdc++.h> using namespace std; ,D=; int d,k,n,a[N][D] ...

  7. XAMPP本地服务器打不开解决方案

    第一步:先开启相关服务:如图 第二步:在浏览器上输入localhost:端口号,(或127.0.0.1:端口号),按回车,就成功登陆本地服务器. =========================== ...

  8. vue使用动态渲染v-model输入框无法输入内容

    最近使用ElementUI框架,在动态渲染表单的时候,表单框无法输入内容,但是绑定model的数据是会发生变化 解决方法: 将动态生成的表单对象,深拷贝到 data 对象中 <el-date-p ...

  9. Django基础-01

    Django 是基于 Python,所有的 Django 代码都是用Python写成的. Django 特点 强大的数据库功能 拥有强大的数据库操作接口(QuerySet API),如需要也能执行原生 ...

  10. Python 随笔-1

    python的发展史: python 2.7            July 3,2010  目前业内主流使用的工业版本 主讲3.0 32bit = 内存的最大寻址空间为2*32    4G的空间 6 ...