All MicroEvals
Write a function to sort a given matrix in ascending order a...
Create MicroEval
Header image for Write a function to sort a given matrix in ascending order a...

Write a function to sort a given matrix in ascending order a...

Prompt

Write a function to sort a given matrix in ascending order according to the sum of its rows. Your function should satisfy these tests: ```python assert sort_matrix([[1, 2, 3], [2, 4, 5], [1, 1, 1]])==[[1, 1, 1], [1, 2, 3], [2, 4, 5]] assert sort_matrix([[1, 2, 3], [-2, 4, -5], [1, -1, 1]])==[[-2, 4, -5], [1, -1, 1], [1, 2, 3]] assert sort_matrix([[5,8,9],[6,4,3],[2,1,4]])==[[2, 1, 4], [6, 4, 3], [5, 8, 9]] ```

Answer guidance

Reference solution: def sort_matrix(M): result = sorted(M, key=sum) return result

Drag to resize
Drag to resize
Drag to resize