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

how to sort a list of dictionary by value in descending order?

1. new_list = sorted(old_list, key=lambda k: k['key'], reverse=True)
/*use reverse=False for ascending order*/
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 :: python initialize multidimensional list 
Python :: how to wait in python 
Python :: python discord bot join voice channel 
Python :: how can I sort a dictionary in python according to its values? 
Python :: cv2.imwrite save to folder 
Python :: popups in tkinter 
Python :: random character generator python 
Python :: import status in django rest framework 
Python :: horizontal line for pyplot 
Python :: save numpy arrayw with PIL 
Python :: python join array of ints 
Python :: python get human readable file size 
Python :: heat map correlation seaborn 
Python :: fill missing values with 0 pandas 
Python :: comment dériver une classe python 
Python :: ban discord.py 
Python :: panda select rows where column value inferior to 
Python :: how to get ipconfig from python 
Python :: get max float value python 
Python :: python selenium scroll all down 
Python :: distance euc of two arrays python 
Python :: opencv get area of contour 
Python :: pil get image size 
Python :: E: Unable to locate package python3-pip 
Python :: python pil invert image color 
Python :: django filter not equal to 
Python :: print two digits after decimal python 
Python :: tkinter maximum window size 
Python :: pandas dataframe convert nan to string 
Python :: python flatten dict 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =