Write a program to sort Dictionary by key-value Summation and print it


Topic: Write a program to sort Dictionary by key-value Summation and print it

Solution

test_dict = {3: 5, 1: 3, 4: 6, 2: 7, 8: 1} 
res = sorted(test_dict.items(), key=lambda sub: sub[0] + sub[1]) 
  
res = {sub[0]: sub[1] for sub in res} 
  
print("The sorted result : " + str(res)) 



List all Python Programs