dic = {'a':31, 'bc':5, 'c':3, 'asd':4, 'aa':74, 'd':0}
dict= sorted(dic.items(), key=lambda d:d[0])
print dict

dic = {'a':1, 'bc':5, 'c':3, 'asd':4, 'aa':74, 'd':0}
dict= sorted(dic.items(), key=lambda d:d[1], reverse = True)
print(dict)

结果

[('a', 31), ('aa', 74), ('asd', 4), ('bc', 5), ('c', 3), ('d', 0)]
[('aa', 74), ('bc', 5), ('asd', 4), ('c', 3), ('a', 1), ('d', 0)]
[Finished in 0.0s]

 

数组排序 https://www.cnblogs.com/kaibindirver/p/12700085.html

相关文章:

  • 2022-02-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-01
  • 2021-11-28
  • 2021-06-30
  • 2022-12-23
猜你喜欢
  • 2021-09-29
  • 2022-12-23
  • 2021-12-22
  • 2022-01-17
  • 2022-12-23
  • 2021-07-20
相关资源
相似解决方案