python 3.6闭包+循环获取出字典中所有的值并保存在list中
2018-02-22 17:38
513 查看
def list_test():
list1=[]
def list_all_dict(a):
#检测字段类型
if isinstance(a,dict):
for x in range(len(a)):
temp_key=list(a.keys())[x]
temp_value=a[temp_key]
if isinstance(temp_value,dict):
list_all_dict(temp_value)
else:
list1.append(temp_value)
list_all_dict(a)
return list1
if __name__=="__main__":
a={"sex":"eee","name":{"sex":"de","ede":"egg"}}
print(list_test())
list1=[]
def list_all_dict(a):
#检测字段类型
if isinstance(a,dict):
for x in range(len(a)):
temp_key=list(a.keys())[x]
temp_value=a[temp_key]
if isinstance(temp_value,dict):
list_all_dict(temp_value)
else:
list1.append(temp_value)
list_all_dict(a)
return list1
if __name__=="__main__":
a={"sex":"eee","name":{"sex":"de","ede":"egg"}}
print(list_test())
相关文章推荐
- 获取FTP上的所有文件名,保存到List<String>中
- python 关于获取某一目录下的所有文件名并保存至txt文件
- python for 循环 一个 list 获取index
- python再复习(2)list、tuple、条件判断和循环、字典和set
- python获取所有链接保存到数据表并依次打开
- Python3学习笔记【基础3--list,tuple,if条件判断,for/while循环,dict字典,set集合】
- python获取父类的子类(遍历,递归),并循环执行所有子类的某一方法
- 利用python.os.listdir获取文件夹中所有文件名
- Python3基础 dict keys+values 循环打印字典中的所有键和值
- Python爬虫项目,获取所有网站上的新闻,并保存到数据库中,解析html网页等(未完待续)
- Python - 两个列表(list)组成字典(dict)
- Python3基础 list range与for循环配合输出等差数列
- 如何获取Python中list的子集
- 列表(list)和字典(dict)数据排序 Python
- TypeError: cannot concatenate 'str' and 'list' objects和Python读取和保存图片
- Python 列表(list)、字典(dict)、字符串(string)常用基本操作小结
- 获取python的list中含有重复值的index方法
- Python中循环后使用list.append()数据被覆盖问题的解决
- python学习九:SocektServer学习、bisect、list的sort详解、清空字典的两种方法、zip初探
- python获取指定目录下所有文件名列表的方法