63. Problem to sort a list by the sum of sublists in Python.

In this Python list program, we will take a user input as a list of lists and sort a list by the sum of sublists with the help of the below-given steps.

Sort list by sum of sublists:

Steps to solve the program
  1. Take a list of lists as input.
  2. Sort the list by the sum of sublists using sorted() and set the key=sum.
  3. Print the output to see the result.
				
					#Input list
list1 = [[3, 5, 6], [2, 1, 3], [5, 1, 1], 
        [1, 2, 1], [0, 4, 1]]

#Printing output
print(sorted(list1, key=sum))
				
			

Output :

				
					[[1, 2, 1], [0, 4, 1], [2, 1, 3], [5, 1, 1], [3, 5, 6]]
				
			

Related Articles

Maximum and minimum from the heterogeneous list

Extract strings of specified sizes from the list

Leave a Comment