Nov-20-2019, 07:39 AM
(This post was last modified: Nov-20-2019, 07:39 AM by newbieAuggie2019.)
(Nov-19-2019, 09:57 PM)Reldaing Wrote: This was just an example of what i've made to switch lines. Now , I want to switch colums but I don't know how to do it, even if i tried...Hi!
Maybe you could do something like this (but probably there is a better way):
def changeColumns(c,d): 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]] print(f"This is array 'a' with original columns:\n") for i in range(len(a)): for j in range(len(a[i])): print(a[i][j], end=' ') print() print(f"\nThis is array 'a' with transposed columns:\n") for x in range(0,9): a[x][c],a[x][d]= a[x][d],a[x][c] for i in range(len(a)): for j in range(len(a[i])): print(a[i][j], end=' ') print() changeColumns(3,6)with the self-explanatory output:
Output:This is array 'a' with original columns:
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
This is array 'a' with transposed columns:
1 2 3 7 5 6 4 8 9
4 5 6 1 8 9 7 2 3
7 8 9 4 2 3 1 5 6
2 3 1 8 6 4 5 9 7
5 6 4 2 9 7 8 3 1
8 9 7 5 3 1 2 6 4
3 1 2 9 4 5 6 7 8
6 4 5 3 7 8 9 1 2
9 7 8 6 1 2 3 4 5
>>>
All the best,
newbieAuggie2019
"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs
"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs