luft·mensch - matrix

How to transpose a matrix

Python is such an expressive language. For instance, you can transpose a matrix in one line:

def transpose(matrix):
    return zip(*matrix)

>>> m = [(1, 2, 3), (4, 5, 6)]
>>> transpose(m)
[(1, 4), (2, 5), (3, 6)]
more ...