0

I have list1

list1 = ["a", "a", "b", "c", "d"]

I have another list2

list2 = ["a", "d"]

I want the output as follows

out = ["a", "a", "d"]

I am doing following

> l1 = set(list1)
>>> l2 = set(list2)
>>> l1.intersection(l2)

But I am loosing duplicates of list1 here. The lists are in actual pretty big. Can't run loop. I need to use some fast efficient way only.

user3664020
  • 2,980
  • 6
  • 24
  • 45
  • @idjaw please check my last line. I don't want loop. – user3664020 Feb 18 '16 at 13:38
  • 3
    I don't think this is possible without a loop of some sort. Even `set.intersection` will use a loop internally. The list comprehension in the dupe answer seems just right to me. – tobias_k Feb 18 '16 at 13:40

0 Answers0