Dev Helpers

Python / Lists and tuples

Transpose a matrix

Dev Helpers · September 26, 2026

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

Worked example

matrix = [[1, 2, 3], [4, 5, 6]]
print(list(zip(*matrix)))

Result

[(1, 4), (2, 5), (3, 6)]

Implementation notes

A transposed zip is an iterator of tuples. Materialize it only when repeated traversal or indexed access is part of the consumer's contract.

Try it yourself

Try a missing trailing cell, then decide between strict validation and padding.

Open the Python example →

Editorial date September 26, 2026 · Published December 6, 2026

Related articles

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.

Enumerate from one

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