-3

I am having two lists with repeating values and I wanted to take the intersection of the repeating values along with the values that have occurred only once in any one of the lists. I am just a beginner and would love to hear simple suggestions!

1 Answers1

0

Method 1

l1=[1,2,3,4]
l2=[1,2,5]
intersection=[value for value in l1 if value in l2]
for x in l1+l2:
    if x not in intersection: 
        intersection.append(x)
print(intersection)

Method 2

print(list(set(l1+l2)))
Suyash Jawale
  • 190
  • 2
  • 13