python行转列

lista=[[1,2,3],[4,5,6],[7,8,9],[10,11,12]] 
ls = []
lst = []
for i in range(len(lista[0])):
    for j in lista:
        ls.append(j[i])
    lst.append(ls)
    ls = []
for i in lst:
    for j in i:
        if j == i[-1]:
            print(j)
        else:
            print(j,end=",")
1,4,7,10
2,5,8,11
3,6,9,12
lista=[[1,2,3],
[4,5,6],
[7,8,9],
[10,11,12]] 

ls = [[i[j] for i in lista] for j in range(len(lista[0]))]
print(ls)
[[1, 4, 7, 10], [2, 5, 8, 11], [3, 6, 9, 12]]

你可能感兴趣的:(python3)