Remove duplicates from a Python list while preserving order


Python tip:

You can use a dictionary to remove duplicates from a list while preserving the order of elements:

users = ["Jan", "Mike", "Marry", "Mike"]

print(list({user: user for user in users}))
# => ['Jan', 'Mike', 'Marry']

A dictionary preserves the insertion order.