One of the inbuilt libraries in Python is zip. It can be utilized to transpose a matrix by performing an Unzip followed by zip. Sample code below.
Python comes with many inbuilt libraries zip is among those. The??zip()??function returns an iterator of tuples based on the??iterable??object. In order to get the transpose of the matrix first, we need to unzip the list using??*??operator then zip it.
inputMatrix = [ [7, 14, 21], [1, 2, 3] ]
Output will be as follows:
[ (7, 1), (14, 2), (21, 3) ]