python remove duplicates from list

Suppose we have python list with duplicates content we need to remove duplicates from list we can use dict.fromkeys

mylist = [1, 2, 2, 3, 4]
mylist = list(dict.fromkeys(mylist))
print(mylist)

Leave a Reply

Your email address will not be published. Required fields are marked *