How to remove duplicates from a list
How to remove duplicates from a list?
Starting with Python 3.7, dictionary is insertion-ordered. So, dict.fromkeys(mylist) will remove the duplicates from a list preserving the original order of the list.
items = [1, 2, 0, 1, 3, 2] list(dict.fromkeys(items))
[1, 2, 0, 3]
items = [1, 2, 0, 1, 3, 2] [*dict.fromkeys(items)]
[1, 2, 0, 3]
items = [1, 2, 0, 1, 3, 2] list(set(items))
[0, 1, 2, 3]