- map 排序
map_xxx ={}
map_xxx[1] ='a'
map_xxx[3] = 'c'
map_xxx[2] = 'b'
for k, v in map_xxx.items():
print(k)
result = sorted(map_xxx.keys())
result = sorted(map_xxx.items(), key=lambda x:x[0])
for item in result:
print(item)
- 二维数组排序
listA = [('a', 1), ('c', 3), ('d', 4), ('b', 2)]
sorted(listA, key=lambda x:x[1])
输出结果为:
[('a', 1), ('b', 2), ('c', 3), ('d', 4)]