Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

sort dict by value python 3

>>> d = {"aa": 3, "bb": 4, "cc": 2, "dd": 1}
>>> for k in sorted(d, key=d.get, reverse=True):
...     k, d[k]
...
('bb', 4)
('aa', 3)
('cc', 2)
('dd', 1)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #sort #dict #python
ADD COMMENT
Topic
Name
4+9 =