a_dic= {'a': {'1': 3}, 'b': {'5': 4}, 'c': {'3': 1}, 'd': {'2': 99}}
b_= sorted(a_dic.values(), key=lambda item: list(item.keys())[0])
print(b_)
example_list= [5, 0, 6, 1, 2, 7, 3, 4]
result_list= sorted(example_list, key=lambda x: -x)
print(result_list)
array= [{"age": 20, "name": "a"}, {"age": 25, "name": "b"}, {"age": 10, "name": "c"}]
array_= sorted(array, key=lambda x: x["age"])
print(array_)
L= [('d', 2), ('a', 4), ('b', 3), ('c', 2)]
l= sorted(L, key=lambda x: x[1])
print(l)
# 先按照成绩降序排序,相同成绩的按照名字升序排序
d1= [{'name':'alice', 'score':38}, {'name':'bob', 'score':18}, {'name':'darl', 'score':28}, {'name':'christ', 'score':28}]
d1_= sorted(d1, key=lambda x: (-x['score'], x['name']))
print(d1_)
a_dic= {'a': {'1': 3}, 'b': {'5': 4}, 'c': {'3': 1}, 'd': {'2': 99}}
print(a_dic.values())
a_= sorted(a_dic.values(), key=lambda x: list(x.keys()))
print(a_)
arr_= [{'1': 3}, {'5': 4}, {'3': 1}, {'2': 99}]
brr_= sorted(arr_, key=lambda item: list(item.keys())[0])
print(brr_)
网友评论