Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python: get values from dictionary of dictionaries

I have a dictionary of dictionaries that looks like this:

{'info': {'status': 'OK',
 'data': {'account': [{'currency': 'USD',
 'name': 'United States Dollar',
 'amount': '100'
 'used': '20',
 'total': '120'},
{'currency': 'EUR',
 'name': 'Euro',
 'amount': '150',
 'used': '35',
 'total': '185'}]}},
 'USD': {'amount': 100, 'used': 20, 'total': 120},
 'EUR': {'amount': 150, 'used': 35, 'total': 185},
 'amount': {'USD': 100, 'EUR': 150},
 'used': {'USD': 20, 'EUR': 35},
 'total': {'USD': 120, 'EUR': 185}}

What I want to get from this is a currency list:

currency_list = ['USD','EUR']

and I would like to get a currency name list:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

currency_list = ['United States Dollar','Euro']

How can I access the dictionaries?

Thank you

>Solution :

given that this info you posted in a var dic just do:

currency_list = [value["currency"] for value in dic["info"]["data"]["account"]]

currency_list_name = [value["name"] for value in dic["info"]["data"]["account"]]

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading