I have two lists:
List1 = ['One', 'Two', 'Three', 'Five', 'Seven', 'Ten', ' Two', 'One']
List2 = ['Nine', 'Two', 'Seven', 'Five' , 'Five', 'Three', 'One', 'One']
The lists are of the same size.
What I want is, to match list1 with list2 by indexes and remove the matching items in list2 if the corresponding indexed item is the same. Otherwise it shouldn’t remove the items. Duplicates can exist in non indexed positions in the Newlist2.
This is what I expect:
List1:#Same as the previous
NewList2 = ['Nine', 'Seven', 'Five', 'Three', 'One']
NewList2 = [ y for (x, y) in zip(List1, List2) if x != y ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With