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 retrieve dictionary's unquoted values

{'CMC Threat Intelligence': {'detected': False, 'result': 'clean site'}, 'Snort IP sample list': {'detected': True, 'result': 'clean site'}, '0xSI_f33d': {'detected': False, 'result': 'unrated site'}}

This is a sample result (value) of a dictionary’s key. If I use:

for i in result[key]:
    print(i)

it will return:

CMC Threat Intelligence
Snort IP sample list
0xSI_f33d

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

But the question is how would I retrieve the keys or values of the dictionaries inside, which are the unquoted values of the quoted keys of the main result.

For example, how would I return the values of those where the 'detected' = True Or the value of 'result' where the value is 'clean site'. Thanks

>Solution :

Use result[key].items() to loop over both the keys and values of the dictionary. Then you can access values from the nested dictionary.

for name, d in result[key].items():
    print(f'{name}: {d['result']}')

This will print:

CMC Threat Intelligence: clean site
Snort IP sample list: clean site
0xSI_f33d: unrated site
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