Generation

generate functionMon, 26 Dec 2022

A matrix matrix is given. matrix = [ [0,1,2,4,8], [6,2,2,1,9], [3,3,3,3,3], [4,6,7,1,2], [5,7,3,4,0] ] Write code (in pure Python, no third-party libraries) that will transpose it (that is, make columns out of rows) into matrix_t: matrix_t = [ [0, 6, 3, 4, 5], [1, 2, 3, 6, 7], [2, 2, 3, 7, 3], [4, 1, 3, 1, 4], [8, 9, 3, 2, 0] ]

def transpose(matrix): return list(map(list, zip(*matrix))) transpose(matrix)

Questions about programming?Chat with your personal AI assistant