Dev Helpers

Python / Lists and tuples

Unpack with a remainder

Dev Helpers · September 7, 2026

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

Worked example

first, *middle, last = [1, 2, 3, 4]
print(first, middle, last)

Result

1 [2, 3] 4

Implementation notes

The remainder binding is a new list, even when it contains just one element. That distinction matters when forwarding the unpacked fields into another function.

Try it yourself

Compare a header-only record with a completely empty record.

Open the Python example →

Editorial date September 7, 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.

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.

Enumerate from one

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