I have two lists
list1 = [\'image1.png\', \'image2.png\', \'image3.png\', \'image3.png\'] list2 = [\'image1.pdf\', \'image2.eps\', \'image3.ps\']
Use a list comprehension with set:
set
list1 = ["image1.png", "image2.png", "image3.png", "image3.png"] list2 = ["image1.pdf", "image2.eps", "image3.ps"] print [x for x in set(list1) for y in set(list2) if x.split('.')[0] == y.split('.')[0]]
Output:
['image1.png', 'image2.png', 'image3.png']