a={'a':{'b':{'c':{'d':'e'}},'f':'g'},'h':'i'}

def show(myMap):

for str in myMap.keys():
secondDict=myMap[str]
print str
if type(myMap[str]).__name__=='dict':
for key in secondDict.keys():
if type(secondDict[key]).__name__=='dict':
print key
show(secondDict[key])
else:
print key
print secondDict[key]
else:
print myMap[str]

show(a)

通过递归来实现遍历字典中的所有元素。效率可能比较低。

python遍历字典元素的更多相关文章

  1. Python遍历字典

    1.遍历key值 1 >>> d = {'Python':'astonishing', 'C++':'complicated', 'Java':'versatile'} 2 > ...

  2. python 遍历字典中的键和值

    #遍历字典中的所有键和值 zd1={"姓名":"张三","年龄":20,"性别":"女"} zd2= ...

  3. python检查字典元素是否存在类似php中isset()方法

    PHP中isset()方法来检查数组元素是否存在,在Python中无对应函数,在Python中一般可以通过异常来处理数组元素不存在的情况,而无须事先检查 Python的编程理念是“包容错误”而不是“严 ...

  4. Python遍历字典dict的几种方法

    #!/usr/bin/python dict={"a":"apple","b":"banana","o&quo ...

  5. python 遍历字典

    dict={"a":"apple","b":"banana","o":"orange&qu ...

  6. python 删除字典元素

    myDict = {,,,} print(myDict) if 'a' in myDict: del myDict['a'] print(myDict)

  7. Python简单遍历字典及删除元素的方法

    Python简单遍历字典及删除元素的方法 这篇文章主要介绍了Python简单遍历字典及删除元素的方法,结合实例形式分析了Python遍历字典删除元素的操作方法与相关注意事项,需要的朋友可以参考下 具体 ...

  8. python 取出字典的键或者值/如何删除一个字典的键值对/如何遍历字典

    先定义一个字典并直接进行初始化赋值 my_dict = dict(name="lowman", age=45, money=998, hourse=None) 1.取出该字典所有的 ...

  9. python中字典的循环遍历的两种方式

    开发中经常会用到对于字典.列表等数据的循环遍历,但是python中对于字典的遍历对于很多初学者来讲非常陌生,今天就来讲一下python中字典的循环遍历的两种方式. 注意: python2和python ...

随机推荐

  1. Loadrunner之文件的上传(八)

    老猪提供: https://mp.weixin.qq.com/s?__biz=MzIwOTMzNDEwNw==&mid=100000013&idx=1&sn=624f5bc74 ...

  2. 2016中国大学生程序设计竞赛 - 网络选拔赛 1001 A water problem (大数取余)

    Problem Descripton Two planets named Haha and Xixi in the universe and they were created with the un ...

  3. Oracle Sql优化之Merge 改写优化Update

    1.待改写语句如下 update table1 f )),) ,),)), f.jine2 )),) from table2 e where e.kjqj=f.kjqj=e.gs=f.gs and e ...

  4. PAT (Advanced Level) 1109. Group Photo (25)

    简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...

  5. Talking about Health

    George: Doctor, what is the best way to stay healthy? Dictor: Having a good diet is probably the mos ...

  6. storm第一篇--概念,例子,参数优化

    1 概念 目前最新的0.8.0版本里面 worker -> 进程.一个worker只能执行同一个spout/bolt的task,一个worker里面可以有多个executor. executor ...

  7. linux下ssh端口的修改和登录

    linux下ssh端口的修改和登录 首先修改配置文件 vi /etc/ssh/sshd_config 找到#Port 22一段,这里是标识默认使用22端口,添加如下一行: Port 50000 然后保 ...

  8. Hibernate用Oracle的sequence生成自增Id

    <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBL ...

  9. 丑数<数学技巧>

    题意:丑数就是质因子只有2,3,5 ,7,的数,另外1也是丑数.求第n(1=<n<=5842)个丑数,n=0,结束. 思路:.3.5或者7的结果(1除外).那么,现在最主要的问题是如何排序 ...

  10. UIButton 解析

    IOS之按钮控件--Button全解析及使用 转载自:forget  IOS开发中伴随我们始终的 最常用的几个空间之一 -- UIButton 按钮,对于button今天在此做一些浅析,并介绍下主流用 ...