Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

sort a dictionary by value then key

d = {'apple': 2, 'banana': 3, 'almond':2 , 'beetroot': 3, 'peach': 4}
[v[0] for v in sorted(d.items(), key=lambda kv: (-kv[1], kv[0]))]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #sort #dictionary #key
ADD COMMENT
Topic
Name
1+3 =