NoahVerner
NoahVerner

Reputation: 877

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?

Upvotes: 0

Views: 29

Answers (1)

Matthew Barlowe
Matthew Barlowe

Reputation: 2328

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

Upvotes: 1

Related Questions