Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

So sánh hai List trong Python

Dùng set intersection tìm common elements.

Ví dụ

>>> a = [1, 2, 3, 4, 5]
>>> b = [9, 8, 7, 6, 5]
>>> set(a) & set(b)
{5}

Hoặc set(a).intersection(set(b)).