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 the values of dictionary python?

I have the below python dictionary stored as dictPython

{
    "paging": {"count": 10, "start": 0, "links": []},
    "elements": [
        {
            "organizationalTarget~": {
                "vanityName": "vv",
                "localizedName": "ViV",
                "name": {
                    "localized": {"en_US": "ViV"},
                    "preferredLocale": {"country": "US", "language": "en"},
                },
                "primaryOrganizationType": "NONE",
                "locations": [],
                "id": 109,
            },
            "role": "ADMINISTRATOR",

        },
    ],
}

I need to get the values of vanityName, localizedName and also the values from name->localized and name->prefferedLocale.

I tried dictPython.keys() and it returned dict_keys(['paging', 'elements']).
Also I tried dictPython.values() and it returned me what is inside of the parenthesis({}).

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

I need to get [vv, ViV, ViV, US, en]

>Solution :

What about:

dic = {
    "paging": {"count": 10, "start": 0, "links": []},
    "elements": [
        {
            "organizationalTarget~": {
                "vanityName": "vv",
                "localizedName": "ViV",
                "name": {
                    "localized": {"en_US": "ViV"},
                    "preferredLocale": {"country": "US", "language": "en"},
                },
                "primaryOrganizationType": "NONE",
                "locations": [],
                "id": 109,
            },
            "role": "ADMINISTRATOR",
        },
    ],
}
base = dic["elements"][0]["organizationalTarget~"]
c = base["name"]["localized"]
d = base["name"]["preferredLocale"]
output = [base["vanityName"], base["localizedName"]]
output.extend([c[key] for key in c])
output.extend([d[key] for key in d])

print(output)

outputs:

['vv', 'ViV', 'ViV', 'US', 'en']
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