Use the set intersection() method to find the intersection of two lists in Python. First Convert the lists to sets using set(iterable) then use intersection() with these two sets to get the intersection.
Example intersection of two lists in Python
Simple example code finds the intersection of list1 and list2.
list1 = [1, 2, 3] list2 = [1, 3, 5] res = set.intersection(set(list1), set(list2)) print(list(res))
Do comment if you have any doubts or suggestions on this python Python intersection code.
Note: IDE: PyCharm 2021.1.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.