Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def sum_prod_diags(matrix):
- n = len(matrix)
- psum =[1] * (2*n-1)
- pdif = {}
- n = len(matrix)
- for i in range(0, n ):
- for j in range(0, len(matrix[i])):
- dif = i-j
- if (dif in pdif):
- pdif[dif] *= matrix[i][j]
- else:
- pdif[dif] = matrix[i][j]
- psum[i+j] *= matrix[i][j]
- a = 0
- for i in range(0, len(psum)): a += psum[i]
- b = 0
- for key in pdif:
- b += pdif[key]
- return b-a
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement