temp_dict = {
"axiaoming": 16."bxiaoli": 18."cxiaoxue": 19."dxiaolin": 20."fxiaojuan": 21."exiaolu": 17,
}
temp_list_test = [
('cxiaoxue'.19),
('exiaolu'.17),
('dxiaolin'.20),
('bxiaoli'.18),
('axiaoming'.18),
('fxiaojuan'.21)]if __name__ == "__main__": # sort a nested list (multidimensional array) print(f"temp_list_test before = {temp_list_test}")
temp_list_test.sort(key=lambda x: (x[1], x[0], reverse=False) #1The second element is in the same order0Print (f"temp_list_test after = {temp_list_test}"If the dictionary is sorted by value, the output is a list, and each element in the list is a tuple, as follows: temp_list = sorted(temp_dict.items(), key=lambda item: item[1], reverse=True) # print(f"temp_list = {temp_list}")
temp_list = sorted(temp_dict.items(), key=lambda item: item[0], reverse=True) # print(f"temp_list = {temp_list}")
Copy the code