# Doubt in Lists (Week 5)

In the list exercise, am getting type error. Please suggest.

def square_matrix_power(A,n):

``````output=[item[:] for item in A]

temp=[item[:] for item in A]

for i in range (n-1):

output[0][0]=A[0][0]*temp[0][0]+A[0,1]*temp[1,0]

output[0][1]=A[0][0]*temp[0][1]+A[0,1]*temp[1,1]

output[1][0]=A[1][0]*temp[0][0]+A[1,1]*temp[1,0]

output[0][0]=A[1][0]*temp[0][1]+A[1,1]*temp[1,1]

temp=[item[:] for item in output]

return output
``````

TypeError Traceback (most recent call last)
in ()
----> 1 print(square_matrix_power(A,2))

in square_matrix_power(A, n)
3 temp=[item[:] for item in A]
4 for i in range (n-1):
----> 5 output[0][0]=A[0][0]*temp[0][0]+A[0,1]*temp[1,0]
6 output[0][1]=A[0][0]*temp[0][1]+A[0,1]*temp[1,1]
7 output[1][0]=A[1][0]*temp[0][0]+A[1,1]*temp[1,0]

TypeError: list indices must be integers or slices, not tuple

That’s because you’ve used A[0,1]
Note that we cannot index a list like that, but we can use such notation to index numpy arrays.

So just replace it with A[0][1].

thaks, have done that. Now there’s no error but I’m getting A as the answer despite changing the value of n

You can refer to this post.