Nov-19-2019, 09:13 PM
Hi, I'm looking for switching two columns in a table. I made a function , but I doon't know the syntax of an array switching in python . Could you guys help me please? Thx
def changeColumns(): a = [[1, 2, 3, 4, 5, 6, 7, 8, 9], [4, 5, 6, 7, 8, 9, 1, 2, 3], [7, 8, 9, 1, 2, 3, 4, 5, 6], [2, 3, 1, 5, 6, 4, 8, 9, 7], [5, 6, 4, 8, 9, 7, 2, 3, 1],[8, 9, 7, 2, 3, 1, 5, 6, 4], [3, 1, 2, 6, 4, 5, 9, 7, 8], [6, 4, 5, 9, 7, 8, 3, 1, 2], [9, 7, 8, 3, 1, 2, 6, 4, 5]] a[1,2,3,4,5,6,7,8,9][0],a[1,2,3,4,5,6,7,8,9][1]= a[1,2,3,4,5,6,7,8,9][1],a[1,2,3,4,5,6,7,8,9][0] #This is what i want to fix for i in range(len(a)): for j in range(len(a[i])): print(a[i][j], end=' ') print()