Write a Python function to Sort a List of Dictionaries by the Sum of their Values and print it


Topic: Write a Python function to Sort a List of Dictionaries by the Sum of their Values and print it

Solution

test_list = [{1 : 3, 4 : 5, 3 : 5}, {1 : 7, 10 : 1, 3 : 10}, {1 : 100}, {8 : 9, 7 : 3}]
def func(test_list):
    return sum(list(test_list.values()))
for i in test_list:
  test_list.sort(key=func) 
print(test_list)



List all Python Programs