python script to sort a dictionary by value code example
Example 1: how can I sort a dictionary in python according to its values?
s = {1: 1, 7: 2, 4: 2, 3: 1, 8: 1}
k = dict(sorted(s.items(),key=lambda x:x[0],reverse = True))
print(k)
Example 2: sorting-a-dictionary-by-value-then-by-key
[(14,2), (12,2), (9,1)] # output from print
[(90,4), (99,3), (101,1), (100,1), (92,1)]