python - 对嵌套字典列表进行排序
问题描述
我有一个大型嵌套字典,需要从中排序和提取数据,但我不知道如何解决这个问题。这是dict
表格:
mydict = {Person 1 : [{'2017-06-02': {'Country A': {'City 1': {'Population': '0', 'Temp': '10'}}}, '2016-06-02': {'Country B': {'City 2' :{'Population':'1'}}}]
我可以使用什么方法按日期对列表进行排序并在之后对其进行迭代?
注意:实际的字典有更多的条目
解决方案
不确定这是否是您要搜索的内容
mydict = {'Person 1' : [{'2017-06-02': {'Country A': {'City 1': {'Population': '0', 'Temp': '10'}}}, '2015-06-02': {'Country A': {'City 1': {'Population': '0', 'Temp': '10'}}}}]}
od = collections.OrderedDict(sorted(mydict["Person 1"][0].items()))
推荐阅读
- c# - 通过 Visual Studio C# 连接到位于 Web (freemysqlhosting.net) 上的远程数据库
- java - 我不能将布尔值用作整数
- python - 使用 bs4 和 selenium 进行 Img 抓取
- javascript - 为什么我不能使用 Javascript 在 Chrome 的新选项卡中打开 dataURI,而我可以在 Firefox 中打开?
- c++ - wxWidgets C++ 的静态编译
- reflection - 函数将函数转换为 CLOS 中的列表。可能吗?
- elixir - Ecto 在关联上运行
- php - 从数据库中拉取图像路径并显示图像
- node.js - 从节点 API 中的 Azure Blob 存储读取内容
- html - 如何防止导航元素包装在 Bootstrap 中