Python find difference between two lists; Through this tutorial, i am going to show you how to find difference between two lists in python.
Python Find Difference of Two Lists
- Python Program to find difference of two lists using Set()
- Python Program to find difference of two lists using for loop
Python Program to find difference of two lists using Set()
# list1 and list2 list1 = [200, 400, 300, 80, 90] list2 = [200, 400, 300, 70, 100] # print both the list print("list1:", list1) print("list2:", list2) # finding and printing differences of the lists print("Difference elements:") print(list (set(list1) - set (list2)))
After executing the program, the output will be:
list1: [200, 400, 300, 80, 90] list2: [200, 400, 300, 70, 100] Difference elements: [80, 90]
Python Program to find difference of two lists using for loop
# list1 and list2 list1 = [200, 400, 300, 80, 90] list2 = [200, 400, 300, 70, 100] list_difference = [] for item in list1: if item not in list2: list_difference.append(item) print(list_difference)
After executing the program, the output will be:
[80, 90]
Recommended Python Tutorials
Recommended:-Python Program to Find Area of Triangle
Recommended:-Python Program to Find the Area of Rectangle
Recommended:-Python Program to Print All Timezones
Recommended:-Python Count the Occurrences in an Array
Recommended:-Python Program to Print Binary Numbers From 1 to N
Recommended:-Python Program to print Elements in a List
Recommended:-Python Program to Swap Characters of Given String
Recommended:-Swap First Two Characters in Each String in Python
Recommended:-Python Split String into Array of Characters
Recommended:-Python Program to Reverse String Using Stack
Recommended:-Python Insert Element at Specified Index in List
Recommended:-Python Program to Swap Two Elements in a List
Recommended:-Python Program to Find LCM of Two Numbers
Recommended:-Python Add and Remove Elements From List