So i have 2 lists and i need to delete everything excluding duplicates - from both.
Example:
a = [1,2,7,8]
b = [1,2,5,9]
output:
[1,2]
ELSE (which is better)
1 2
So i have 2 lists and i need to delete everything excluding duplicates - from both.
Example:
a = [1,2,7,8]
b = [1,2,5,9]
output:
[1,2]
ELSE (which is better)
1 2
You can use intersection:
print(set(a).intersection(set(b)))
>>> {1, 2}
You want to use set
a = [1,2,7,8]
b = [1,2,5,9]
result = list(sorted(set(a).intersection(set(b)))
On top of Maurice's answer, you can avoid calling set on b as it is taken care by intersection.
print(set(a).intersection(b))
You can use list comprehension in this question. Like this:
print([i for i in a for j in b if i==j])