Matrix Transpose in Python

前端 未结 18 1203
甜味超标
甜味超标 2020-11-22 00:21

I am trying to create a matrix transpose function for python but I can\'t seem to make it work. Say I have

theArray = [[\'a\',\'b\',\'c\'],[\'d\',\'e\',\'f\         


        
18条回答
  •  你的背包
    2020-11-22 01:15

    def transpose(matrix):
        listOfLists = []
        for row in range(len(matrix[0])):
            colList = []
            for col in range(len(matrix)):
                colList.append(matrix[col][row])
        listOfLists.append(colList)
    
        return listOfLists
    

提交回复
热议问题