I am trying to find out the sum of the diagonal elements in a matrix. Here, n is the size of the square matrix and a is the matrix. Can someone explain this to me what is happen
def sum_up_diagonals(li):
index = len(li)
first_dia = sum(li[i][i]for i in range(index))
second_dia = sum(li[i][index-i-1]for i in range(index))
return (first_dia,second_dia)