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

check if ALL variables are in one list

Set-up

I have a dictionary variable tags_dict.

I have an if condition that looks like,

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

    if 'seat_height_min' in tags_dict and 'seat_height_max' in tags_dict and 'material_wheels' in tags_dict:
        #do something

Question

How do I write this simpler?

I’d love to do something along the lines of,

if all('seat_height_min','seat_height_max','material_wheels') in tags_dict:
    # do something

but this doesn’t work.

Is there a function that does something like the above?

>Solution :

d = {'a':1,'b':2,'c':3}
all([x in d for x in ['a','b','c']])

the code above 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