How to remove duplicate from list in python

Create a dictionary from given list, using the List items as keys. This will automatically remove any duplicates keys, because dic cannot have duplicate keys.

Example :-- 

>>> list_data = ['a', 'b', 'a', 'c', 'd', 'b', 'c', 'd', 'd']
>>> my_dict = dict.fromkeys(list_data)
>>> list_without_dup = list(my_dict)
>>> print(list_without_dup)
['a', 'b', 'c', 'd']
>>> 

 

Total Views: 625