How to remove duplicate entries from the list Python

def my_function(x):
  return list(dict.fromkeys(x))

mylist = my_function(["a", "b", "a", "c", "c"])

print(mylist)

1. Use the list of items as the key to create the dictionary. This will automatically delete any duplicates, because the dictionary can not have duplicate keys.
2. Then, the dictionary is converted back to the list.

Published 186 original articles · won praise 21 · views 10000 +

Guess you like

Origin blog.csdn.net/sinat_23971513/article/details/105286699