Matrix Transpose in Python

前端 未结 18 1216
甜味超标
甜味超标 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:00

    def transpose(matrix):
       x=0
       trans=[]
       b=len(matrix[0])
       while b!=0:
           trans.append([])
           b-=1
       for list in matrix:
           for element in list:
              trans[x].append(element)
              x+=1
           x=0
       return trans
    

提交回复
热议问题