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 that elements exist within a list Python

Is there a way to check that Elements within list1 are part of list2?
What I’ve tried is down below… But I don’t get an ouput. I’m guessing the ‘in’ function only deals with individual elements?

pattern=['Tacos', 'Pizza']
Foods=['Tacos', 'Pizza', 'Burgers', 'Fries', 'Ice-cream']

if pattern in foods:
    print('yes')

>Solution :

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

You can do it as a simple set logic.

set(pattern).issubset(foods)
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