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

Remove items from lists that doesn't match two lists

I didn’t know how to properly define this question, but here’s the problem.

I have two lists like this:

x = ['Monday', 'Tuesday', 'Wednesday', 'Thursday']
z = ['Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']

I’d like to match up the two lists and remove any items that do not exist in both lists. That means that the output would in this case be:

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

y = ['Wednesday', 'Thursday']

I tried using the zip() function but couldn’t get it to work. Do you have any ideas?

Thanks beforehand.

>Solution :

Do this:

x = ['Monday', 'Tuesday', 'Wednesday', 'Thursday']
z = ['Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
res = list(set(x)&set(z))
print(res)

This would give you the desired result

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