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!
Asked
Active
Viewed 33 times
-3
-
1Please share an example input/output and your attempt to solve the problem. – Asocia Aug 25 '20 at 10:35
-
1`collections.Counter` might be what you're looking for. – tzaman Aug 25 '20 at 10:40
1 Answers
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