Python program to remove duplicate elements in a list

This is a simple python script to remove duplicate elements in a list. The program uses a list with duplicate elements to show how we can remove duplicate elements. It's actually quite simple in Python, First convert the elements using set function this will produce a set of elements with unique elements and convert the set to List. It's that simple !!!

#A list with duplicate elements
a=[1,2,3,1,2]

b=list(set(a))
print('The list before removing duplicate elements',a)
print('The list after removing duplicate elements',b)


Post a comment

Name

Your Comment

Email (We dont publish it)

Comments

Nothing yet..be the first to share wisdom.