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

How to get a key from inside another key in python

Hey does anybody know how I would go about getting the value of a key which is already inside another key like this:

a = {"fruit":[{"oranges":['10']},{"apples":['11']}]}
print(a.get("fruit"))

I can get the value of "fruit" but how would I get the value of "oranges".
Thank you for any help in advance.

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

>Solution :

You just have to access the first element of the list inside fruits, and then access the key inside

print(a['fruit'][0]['oranges']
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