被记住的永远是疯子!
字典排序是很可能会考的面试题:
dic = {'a':10,'b':5,'c':8}
# 1代表按value排序,0代表按key排序
result = sorted(dic.items(),key = lambda x:x[1])
print(result)
默认是升序排序,降序排序用resverse参数
dic = {'a':10,'b':5,'c':8}
# 1代表按value排序,0代表按key排序
result = sorted(dic.items(),key = lambda x:x[1],reverse=True)
print(result)
拜拜~
来源:https://blog.csdn.net/a18612039484/article/details/99866148