Dev Helpers

Python / Lists and tuples

Remove duplicates in order

Dev Helpers · October 9, 2025

An ordered dictionary of keys provides a compact way to deduplicate hashable values in first-seen order.

Worked example

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

Result

[3, 1, 2]

Implementation notes

Two equal values with different display forms collapse to one stored key. Decide whether that first display form should be retained or normalized.

Try it yourself

Compare repeated integers with an input containing an unhashable list.

Open the Python example →

Editorial date October 9, 2025 · Published December 6, 2026

Related articles

Transpose a matrix

Transposing rows into columns assumes a decision about uneven rows. Ordinary zip stops at the shortest input.

Unpack with a remainder

Starred unpacking separates a fixed header from a variable-length tail. It still requires enough elements for the fixed positions.

Flatten one level

A one-level flatten turns a sequence of groups into a sequence of members. Deeper lists remain members in their own right.