Dev Helpers

Python / Dictionaries and sets

Find a symmetric difference

Dev Helpers · May 22, 2026

A symmetric difference contains values found on exactly one side. It works well for comparing membership snapshots where multiplicity is irrelevant.

Worked example

print(sorted({1, 2, 3} ^ {2, 3, 4}))

Result

[1, 4]

Implementation notes

Sets do not preserve the business ordering of two feeds. If a report requires a stable order, sort the resulting identifiers using an explicit key.

Try it yourself

Repeat one value in the incoming list before converting it to a set.

Open the Python example →

Editorial date May 22, 2026 · Published December 6, 2026

Related articles

Run an async function

An async function call creates a coroutine. A top-level runner supplies the event loop that executes it.

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.