Given two lists of integers, we have to find the differences i.e. the elements which are not exists in second lists.
Example:
Input:
List1 = [10, 20, 30, 40, 50]
List2 = [10, 20, 30, 60, 70]
Output:
Different elements:
[40, 50]
Logic:
To find the differences of the lists, we are using set() Method, in this way, we have to explicitly convert lists into sets and then subtract the set converted lists, the result will be the elements which are not exist in the second.
Program to find difference of two lists in Python
Output
Program 2: with mixed type of elements, printing 1) the elements which are not exist in list2 and 2) the elements which are not exists in list1.
Output
need an explanation for this answer? contact us directly to get an explanation for this answer