简体   繁体   中英

Python Dictionary: Output dictionary within a list within a dictionary

I have a dictionary with a lot of keys. One of those keys has a list of dictionaries; i want to extract data from the ladder dictionary.

It looks like this:

Data = {
(...)
Users:[{'username':'X','email':'Y'},{'username':'W','email':'Z'}]
(...)
}

And I want to create a list with all the emails, so that

print(listEmails)
>['Y','Z']

How should I do this?

print([user.get('email') for user in Data['Users']])

That is assuming Users from your sample is actually str - 'Users'

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