I have a matrix as shown below;
matrix=""" 8 1 A A A A 8
8 5 A A A 3 8
7 2 A A 1 4 7
6 1 3 A 2 5 7
2 4 5 A 1 1 1"""
And here's my code block:
lines= [i.strip().split() for i in matrix.splitlines()]
lst=[[lines[i][j] for i in range(len(lines))]for j in range(len(lines[0]))]
h=0
while h<=len(lines[0]):
for i in range(len(lines[0])-1,0,-1):
for j in range(len(lines)-1,-1,-1):
for k in lst:
if k.count('A')==len(lines):
if lines[j][i-1]=='A':
lines[j][i-1]=lines[j][i]
lines[j][i]='A'
h+=1
for line in lines:
print(*(i or " " for i in line) , sep=" ")
If a column full of A's, I want to move that column to the most right side, but my code moves all A's to right. This is my output:
8 1 8 A A A A
8 5 3 8 A A A
7 2 1 4 7 A A
6 1 3 2 5 7 A
2 4 5 1 1 1 A
I want a output something like that:
8 1 A A A 8 A
8 5 A A 3 8 A
7 2 A 1 4 7 A
6 1 3 2 5 7 A
2 4 5 1 1 1 A