def transpose(matrix):
n=0
finalList = []
while n < (len(matrix)):
li = []
for sets in matrix:
li.append(sets[n])
finalList.append(li)
n += 1
return finalList
我试图转置([[1,2]])并返回[[1],[2]]作为结果,但我只得到[[1]]作为回报。有什么想法吗?
答案 0 :(得分:0)
为便于修复,请仅将len(matrix)
部分更改为len(matrix[0])
def transpose(matrix):
n=0
finalList = []
while n < (len(matrix[0])):
li = []
for sets in matrix:
li.append(sets[n])
finalList.append(li)
n += 1
return finalList