How to create a triangular array function

  python

A triangular array is a list whose rows start (or end) at size one and increase (or decrease) by one each row. An example of triangular array is below. The transpose is a triangular array with rows and columns swapped with each other. The two triangular arrays shown below are the transpose of one another.
How can I write a function that takes a triangular array and returns the transpose. Print the original array and the transposed array row by row like in the commented code below. print(array) is not acceptable. Just looking for guidance not the answer

"""
Increasing Triangular Array
 3
 7  1
 5  8 -1
 2 -9  5  0

Transpose of above array
 3  7  5  2
 1  8 -9
-1  5
 0
"""

array = [ [3], [7, 1], [5, 8, -1], [2, -9, 5, 0]]
def transpose(array):
    # code
    return array_t

array_t = transpose(array)

Source: Python Questions

LEAVE A COMMENT