- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to find missing and additional values in two lists?
In set theory, the complement of a set A refers to elements not in A. the relative complement of A with respect to a set B, also termed the difference of Sets A and B. We just apply this principle here. Python has difference function.
Algorithm
Step 1 : first we create two user input list. A & B Step 2 : Insert A and B to a set. Step 3 : for finding the missing values of first list we apply difference function, difference of B from A. Step 4 : for finding the Additional values of first list we apply difference function, difference of A from B. Step 5 : Same procedure apply for Second list also.
Example Code
#To find the missing and additional elements A=list() B=list() n1=int(input("Enter the size of the First List ::")) n2=int(input("Enter the size of the second List ::")) print("Enter the Element of first List ::") for i in range(int(n1)): k=int(input("")) A.append(k) print("Enter the Element of second List ::") for j in range(int(n2)): k1=int(input("")) B.append(k1) # prints the missing and additional elements in first list print("Missing values in first list:", (set(B).difference(A))) print("Additional values in first list:", (set(A).difference(B))) # prints the missing and additional elements in second list print("Missing values in second list:", (set(A).difference(B))) print("Additional values in second list:", (set(B).difference(A)))
Output
Enter the size of the First List :: 6 Enter the size of the second List :: 5 Enter the Element of first List :: 1 2 3 4 5 6 Enter the Element of second List :: 4 5 6 7 8 Missing values in first list: {7, 8} Additional values in first list: {1, 2, 3} Missing values in second list: {1, 2, 3} Additional values in second list: {7, 8}
- Related Articles
- Java program to find missing and additional values in two lists
- C# program to find additional values in two lists
- Python program to find Intersection of two lists?
- C# program to find common values from two or more Lists
- Python program to find Cartesian product of two lists
- Program to find union of two given linked lists in Python
- Program to find minimum difference between two elements from two lists in Python
- Python program to find Union of two or more Lists?
- Python Program to Merge Two Lists and Sort it
- Program to find missing numbers from two list of numbers in Python
- How to compare two DataFrames in Python Pandas with missing values
- C# program to find Intersection of two lists
- Program to find median of two sorted lists in C++
- Python program to list the difference between two lists.
- Compare two columns and add missing values in Excel

Advertisements