Home > Software engineering >  Comparing two lists and printing same value Python
Comparing two lists and printing same value Python

Time:04-22

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"]

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

Help is highly appreciated! :)

CodePudding user response:

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

  • Related