Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python dictionary sort in descending order

dict = {"Python":750,"Java":950,"Ruby":700,"C++":200} 
 
sort_values = sorted(dict.items(), key=lambda y: y[1], reverse=True)

for i in sort_values:
	print(i[0], i[1])
Comment

ascending, descending dict

import operator
d = {1: 2, 3: 4, 4: 3, 2: 1, 0: 0}
print('Original dictionary : ',d)
sorted_d = sorted(d.items(), key=operator.itemgetter(1))
print('Dictionary in ascending order by value : ',sorted_d)
sorted_d = dict( sorted(d.items(), key=operator.itemgetter(1),reverse=True))
print('Dictionary in descending order by value : ',sorted_d)
Comment

PREVIOUS NEXT
Code Example
Python :: django order by foreign key count 
Python :: what is cross entropy loss in pytorch example 
Python :: django group with permission 
Python :: how to split a string with newline in python 
Python :: numpy diff 
Python :: gráfico barras python 
Python :: convert .py to .ipynb file 
Python :: python convert int to hex string 
Python :: python add one month to a date 
Python :: how many columns can a pandas dataframe have 
Python :: find max length of list of list python 
Python :: laplace transform python 
Python :: python enum advanced 
Python :: media pipe install ERROR: Could not find a version that satisfies the requirement mediapipe (from versions: none) 
Python :: python sys.argv 
Python :: hashing in python using chaining in python 
Python :: python create temp file 
Python :: python turtle set screen size 
Python :: matplotlib savefig legend cut off 
Python :: numpy create array with values in range 
Python :: how to copy content of one file to another in python 
Python :: python dictionary multiple same keys 
Python :: tk inter entry 
Python :: get the name of all files in a computer in python 
Python :: streamlit headings;streamlit text 
Python :: gdscript tween 
Python :: os.getcwd() python 3 
Python :: how to take two space separated int in python 
Python :: decrypt vnc password 
Python :: Python connect to a server via RDP 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =