简体   繁体   中英

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()]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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