Remove Duplicates String in a List Python


In this tutorial, you will learn to remove duplicates string in a list python. First, we have to create a list with duplicated data, in this tutorial we will use string. Then, create a dictionary, using the list items as keys. This process will automatically remove any duplicates because dictionaries cannot have duplicate keys (Smart Right?!).  Last, you need to convert the dictionary back into a list.

# Created by inpows
# Visit for more python tutorials

mylist = ["a", "b", "a", "c", "c", "d", "e", "e", "d", "b", "b"]
mylist = list(dict.fromkeys(mylist))

The output will be:

['a', 'b', 'c', 'd', 'e']
Back To Top