def shift_matrix(a):
start_row=0
start_col=0
end_row=len(a[0])-1
end_col=len(a)-1
prev=a[0][0]
while (start_row<end_row and start_col<end_col):
for i in range(start_col,end_col+1):
temp=a[start_row][i]
a[start_row][i]=prev
prev=temp
start_row+=1
for i in range(start_row,end_row+1):
temp=a[i][end_col]
a[i][end_col]=prev
prev=temp
end_col-=1
for i in range(end_col,start_col-1,-1):
temp=a[end_row][i]
a[end_row][i]=prev
prev=temp
end_row-=1
for i in range(end_row,start_row,-1):
temp=a[i][start_col]
a[start_col]=prev
prev=temp
start_col+=1
a[0][0] = prev
a = [[ 1, 2, 3, 4, 5],[16, 17, 18, 19, 6],
[15, 24, 25, 20, 7],[14, 23, 22, 21, 8],
[13, 12, 11, 10, 9]
]
shift_matrix(a)
for r in a:
print(r)
**SO I WROTE THIS PROGRAM TO SHIFT ALL THE VALUES IN AN SPIRAL ARRAY BY 1.
THE ASSIGNMENT a[0][0]= prev throws an error of "'int' object does not support item assignment".
Please help me.
Thanks in advance**
Meh123 0 Newbie Poster
hussainmujtaba -3 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.