Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python - sort dictionary by value

d = {'one':1,'three':3,'five':5,'two':2,'four':4}

# Sort
a = sorted(d.items(), key=lambda x: x[1])

# Reverse sort
r = sorted(d.items(), key=lambda x: x[1], reverse=True)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #sort #dictionary
ADD COMMENT
Topic
Name
2+1 =