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 evaluate if a particular value exists in every single key in a dictionary that has arrays as values on Python?

Let’s say I have the following dictionary in a Python program:

the_dictionary_list = {'Color': ['None', 'Amarillo.png', 'Blanco.png', 'Rojirosado.png', 'Turquesa.png', 'Verde_oscuro.png', 'Zapote.png'], 'Cuerpo': ['None', 'Cuerpo_cangrejo.png'], 'Fondo': ['None', 'Oceano.png'], 'Ojos': ['None', 'Antenas.png', 'Pico.png', 'Verticales.png'], 'Pinzas': ['None', 'Pinzitas.png', 'Pinzotas.png', 'Pinzota_pinzita.png'], 'Puas': ['None', 'Arena.png', 'Marron.png', 'Purpura.png', 'Verde.png']}

How can I verify that the element 'None' exists in every single key from the dictionary above?

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 :

all(['None' in v for k, v in the_dictionary_list.items()])

This loops through the dictionary key value pairs and returns a True or False if 'None' is in the value. And then all checks if they are all true if one is false it will return False if all are True it returns 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