Matrix transposition

From Rosetta Code
Revision as of 12:23, 7 February 2008 by rosettacode>NevilleDNZ (Python)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Task
Matrix transposition
You are encouraged to solve this task according to the task description, using any language you may know.

Transpose an arbitrarily sized rectangular Matrix.

Python

#!/usr/bin/env python
from pprint import pprint
m=((1,  1,  1,   1),
   (2,  4,  8,  16),
   (3,  9, 27,  81),
   (4, 16, 64, 256),
   (5, 25,125, 625));
pprint(zip(*m))

Output:

[(1, 2, 3, 4, 5),
 (1, 4, 9, 16, 25),
 (1, 8, 27, 64, 125),
 (1, 16, 81, 256, 625)]