Lists · Python example
Use dictionary keys to deduplicate a list without losing the original order.
A set removes duplicates but loses order. Dictionary keys also deduplicate, and since Python 3.7 they preserve insertion order.
values = [3, 1, 3, 2, 1, 4, 2]
unique = list(dict.fromkeys(values))
print("Original:", values)
print("Unique:", unique)