Program to find common items from two lists.

Code:

def common_member(a, b):

            a_set = set(a)

            b_set = set(b)

            if (a_set & b_set):

                        print("Common members:",a_set & b_set)

            else:

                        print("No common elements")

a = [1, 2, 3, 4, 5]

print("List1:",a)

b = [5, 6, 2, 8, 9]

print("List2:",b)

common_member(a, b)

 

Output:


Comments

Popular posts from this blog

State use of pep and pip