How to remove duplicates from a list in Python

· 1 min read · Updated March 16, 2026 · beginner
python lists deduplication

The fastest way to remove duplicates while keeping the original order uses a dictionary:

items = [1, 2, 2, 3, 1, 4, 3]
unique = list(dict.fromkeys(items))
print(unique)  # [1, 2, 3, 4]

Since Python 3.7, dictionaries maintain insertion order, making this approach both fast and reliable.

Using a Loop

def remove_duplicates(items):
    seen = set()
    result = []
    for item in items:
        if item not in seen:
            seen.add(item)
            result.append(item)
    return result

print(remove_duplicates([1, 2, 2, 3, 1, 4, 3]))  # [1, 2, 3, 4]

This approach gives you more control over how duplicates are handled.

Common mistake

Using set() directly loses order:

items = [1, 2, 2, 3, 1, 4, 3]
unique = list(set(items))
print(unique)  # [1, 2, 3, 4] — order not preserved

If order matters, use dict.fromkeys() or the loop method.

See Also