Python's dictionary in accordance with the value of the sort

dic_class={'4':3,'5':5,'1':1}
dic_class_sorted = sorted(dic_class, key=dic_class.__getitem__, reverse=True)
print(dic_class_sorted)

  Output:

['5', '4', '1']

sorted Function: returns a dictionary key, Reverse = True, sorted in descending key

Guess you like

Origin www.cnblogs.com/shuangcao/p/12468403.html