Dev Helpers

Python / Lists and tuples

Flatten one level

Dev Helpers · April 25, 2026

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

Worked example

nested = [[1, 2], [3], [4, 5]]
print([item for row in nested for item in row])

Result

[1, 2, 3, 4, 5]

Implementation notes

A string is iterable too. If a group unexpectedly becomes a string, a generic flattening loop can turn a label into individual characters.

Try it yourself

Include an empty group and a group containing another list.

Open the Python example →

Editorial date April 25, 2026 · 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.

Enumerate from one

Human-facing row numbers often start at one while sequence indexes start at zero. enumerate accepts a display offset directly.