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

Comparing two lists and printing same value Python

Is there a way to compare identical values between two lists
and print them by order?

a = ["C4", "B5", "D5", "C6"]

b = ["C0", "B2", "C4", "C6"]

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

I know of set(a).intersection(b) but it does not print in order (values are mixed in different places)

Help is highly appreciated! 🙂

>Solution :

one simple line
[item for item in a if item in b]

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