Advertisement
BERKYT

sum matrix

Dec 19th, 2021
751
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.24 KB | None | 0 0
  1. def sum_matrix(matrix):
  2.     tot = 0
  3.     for x in matrix:
  4.         if not isinstance(x, list):
  5.             tot += x
  6.         else:
  7.             tot += sum_matrix(x)
  8.     return tot
  9.  
  10.  
  11. print(sum_matrix([[1, 2, 3, 1, 4], [1, 2, 4, 1, 6]]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement