How to remove duplicate elements from the list.
I have
list=[1,2,1,2,3,1,3,4]
and I want to drop repeated items. That is, if an item in the list comes two or more times then it is exclude from the list completely. The final list should look like this:
new_list=[4]
In this example 1, 2 and 3 occur at least two time and therefore all these elements are removed from the list
list=[1,2,1,2,3,1,3,4]
new_list = [i for i in set(list)] # wrong; how do I fix this?
print new_list
Please note this is different from set(list)
because set
keeps all items in the list.