- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

When it is required to sort matrix based upon sum of rows, a method is defined that uses ‘sum’ method to determine the result.

Below is a demonstration of the same −

def sort_sum(row): return sum(row) my_list = [[34, 51], [32, 15, 67], [12, 41], [54, 36, 22]] print("The list is :") print(my_list) my_list.sort(key = sort_sum) print("The result is :") print(my_list)

The list is : [[34, 51], [32, 15, 67], [12, 41], [54, 36, 22]] The result is : [[12, 41], [34, 51], [54, 36, 22], [32, 15, 67]]

A method named ‘sort_sum’ is defined that takes a list as a parameter, and returns sum of the elements of the list as output.

A list of list is defined and displayed on the console.

The list is sorted using ‘sort’ method and the key is specified as the previously defined method.

This is the output that is displayed on the console.

- Related Questions & Answers
- Python Program to sort rows of a matrix by custom element count
- Python Program to Sort Matrix Rows by summation of consecutive difference of elements
- C program to sort all columns and rows of matrix
- Program to find matrix for which rows and columns holding sum of behind rows and columns in Python
- Program to find diagonal sum of a matrix in Python
- Python – Sort Matrix by K Sized Subarray Maximum Sum
- Python program to sort table based on given attribute index
- Python Program to Extract Rows of a matrix with Even frequency Elements
- Python - Sort rows by Frequency of K
- Python program to remove rows with duplicate element in Matrix
- Python Program that filters out non-empty rows of a matrix
- Column Sort of a Matrix in Python
- How can Tensorflow be used to sum specific elements/rows of a matrix in Python?
- How to sort a matrix based on one column in R?
- Program to sort out phrases based on their appearances in Python

Advertisements