- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Given three user input lists, our task is to find out common elements from these three lists. Here we are applying intersection method.

Input A=[2, 3, 4, 5, 6] B=[2, 3, 7, 6, 90] C=[2, 3, 45, 34] Common elements=[2, 3]

Step1: input the elements of three lists. Step2: Use intersection method, first convert lists to sets then apply intersection method of two sets and find out common elements then this set intersect with the third set.

def common_ele(my_A, my_B, my_C): my_s1 = set(my_A) my_s2 = set(my_B) my_s3 = set(my_C) my_set1 = my_s1.intersection(my_s2) output_set = my_set1.intersection(my_s3) output_list = list(output_set) print(output_list) if __name__ == '__main__' : # First List A=list() n=int(input("Enter the size of the List")) print("Enter the number") for i in range(int(n)): p=int(input("Size=")) A.append(int(p)) print (A) # Second List B=list() n1=int(input("Enter the size of the List")) print("Enter the number") for i in range(int(n1)): p=int(input("Size=")) B.append(int(p)) print (B) # Third Array C=list() n2=int(input("Enter the size of the List")) print("Enter the number") for i in range(int(n2)): p=int(input("Size=")) C.append(int(p)) print (C) # Calling Function common_ele(A, B, C)

Enter the size of the List 3 Enter the number Size= 2 [2] Size= 1 [2, 1] Size= 2 [2, 1, 2] Enter the size of the List 3 Enter the number Size= 2 [2] Size= 1 [2, 1] Size= 4 [2, 1, 4] Enter the size of the List 4 Enter the number Size= 3 [3] [] Size= 2 [3, 2] [2] Size= 1 [3, 2, 1] [1, 2] Size= 3 [3, 2, 1, 3] [1, 2]

- Related Questions & Answers
- C# program to find common elements in three arrays using sets
- Find common elements in three linked lists in C++
- Python program to find common elements in three sorted arrays?
- C# program to find common elements in three sorted arrays
- Java program to find common elements in three sorted arrays
- Find common elements in list of lists in Python
- Python program to print all the common elements of two lists.
- Find common elements in three sorted arrays in C++
- Find common elements in three sorted arrays by dictionary intersection in Python
- Python Program to find Duplicate sets in list of sets
- Program to find length of longest common subsequence of three strings in Python
- C# program to print all the common elements of two lists
- Program to find the common ratio of three numbers in C++
- C# program to find common values from two or more Lists
- Python Program to Find the first Common Element between the 2 given Linked Lists

Advertisements