Remove Duplicate Element From a List Using set() in Python

Python Program to Remove Duplicate Elements From a List Using set()

# Remove Duplicate Element From a List Using set() in Python
 
# initializing list
test_list = [1, 5, 3, 6, 3, 5, 6, 1, 7, 5, 3, 4]
print ("The original list is : "
		+ str(test_list))

# using set() to remove duplicates from list
test_list = list(set(test_list))

# printing list after removal
# distorted ordering
print ("The list after removing duplicates : "
		+ str(test_list))

Output:

The original list is : [1, 5, 3, 6, 3, 5, 6, 1, 7, 5, 3, 4]
The list after removing duplicates : [1, 3, 4, 5, 6, 7]

About The Author

Leave a Reply