Easy way to remove duplicate items from a list using set.

Tuesday, July 16, 2013

A program to check if a list has any duplicates and if it does it removes them and returns a new list with the items that werent duplicated/removed.
In Python it can be done easily. First make a set from the list and then make a list for that set.
 a_List = list(set(a_List))  
Here is a python example:
 >>> a_List = [1, 2, 3, 3, 2, 2, 4, 5, 5]  
 >>> a_List  
 [1, 2, 3, 3, 2, 2, 4, 5, 5]  
 >>> a_List = list(set(a_List))  
 >>> a_List  
 [1, 2, 3, 4, 5]  
Comments are always welcome!
Have a Happy Python!