将字典词典转换为词典列表 [英] Converting a dictionary of dictionaries to a List of dictionaries

查看:88
本文介绍了将字典词典转换为词典列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有词典字典,有什么可能的方法可以将其转换为词典列表?
如果不是,那么如何使用filter()方法过滤字典中的数据?

I have a dictionary of dictionaries.Is there any possible way to convert it to a list of dictionaries? And if not, then how is the filter() method applied to filter data in a dictionary of dictionaries?

推荐答案

列表理解应该可以完成工作,不需要 filter()

A list comprehension should do the job, no need for filter().

>>> dic_of_dics = {1: {"a": "A"}, 2: {"b": "B"}, 3: {"c": "C"}}

>>> list_of_dics = [value for value in dic_of_dics.values()]

>>>list_of_dics
[{'a': 'A'}, {'b': 'B'}, {'c': 'C'}]

这篇关于将字典词典转换为词典列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆