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 check list of dictionaries for all None values

I have the following list of dictionaries, that currently contain None values:

[{'connections': None}, {'connections': None}, {'connections': None}]

I want to loop through the list of elements, check if each "connections" key in each dictionary is None and return true if so. How can i check if all values are None?

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 can use a generator expression and all to unpack all the dict values in lst and check if they are all None:

out = all(x is None for d in lst for x in d.values())

Output:

True
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