--------------
>>> a {‘a‘: 5, ‘c‘: 3, ‘b‘: 4, ‘e‘: 1, ‘d‘: 2} >>> sorted(a.items()) [(‘a‘, 5), (‘b‘, 4), (‘c‘, 3), (‘d‘, 2), (‘e‘, 1)] >>> sorted(aa.items(),key = lambda d:d[1]) [(‘e‘, 1), (‘d‘, 2), (‘c‘, 3), (‘b‘, 4), (‘a‘, 5)] >>> sorted(aa.items(),key = lambda d:d[1],reverse=True) [(‘a‘, 5), (‘b‘, 4), (‘c‘, 3), (‘d‘, 2), (‘e‘, 1)]
时间: 2024-12-08 11:32:51