Python ProgrammingPython Programming

How to compare common elements in two lists in Python?

Compare common elements

thelist1 = [1, 4, 2, 3, 5, 4]
thelist2 = [3, 4, 5, 9, 10, 11]

set1 = set(thelist1)
print(set1.intersection(thelist2))
{3, 4, 5}