Home > Blockchain >  Python Dictionary: Output dictionary within a list within a dictionary
Python Dictionary: Output dictionary within a list within a dictionary

Time:02-10

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?

CodePudding user response:

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

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

  • Related