简体   繁体   English

将嵌套字典的字典转换为元组列表

[英]Convert dictionary of nested dictionaries into list of tuples

I have a Dictionary of nested dictionaries: 我有一个嵌套字典的字典:

d= {"name": {"weight": 150, "age":20},...."name":{"weight":170, "age":32}}

I want to convert this to a list of tuples, so I can easily sort on both weight and age.... 我想将其转换为元组列表,以便可以轻松地按重量和年龄进行排序。

new_d =[(name,150,20),(name,170,32)]

Any suggestions? 有什么建议么?

使用列表理解:

new_d = [(k, v['weight'], v['age']) for k, v in d.items()]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM