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 check multiple dictionaries for values?

If I have:

d = {'a': 1, 'b': 3}
e = {'a': 2, 'b': 6}
f = {'a': 1, 'b': 4}

How would I check that values of the 'b' key in all dictionaries is above 2 and then execute a function?

I have tried:

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

dicts = [d, e, f]
for i in dicts:
    if i['b'] >= 3:
        func()

However, this calls the function 3 times, whereas I only want to call it once all arguments are met.

>Solution :

dicts = [d, e, f]    
if all([i['b'] >= 3 for i in dicts]):
    func()
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