题解 | #成绩排序#
成绩排序
https://www.nowcoder.com/practice/8e400fd9905747e4acc2aeed7240978b
#应该采用列表排序的形式输出,因为我也使用了字典,发现无论是以key还是value排序都有重复的字段会覆盖掉之前的字段。 n = int(input()) style = int(input()) style = True if style == 0 else False lst = [] for i in range(n): line = input().split() lst.append([line[0], int(line[1])]) lst = sorted(lst, key=lambda x: x[1], reverse=style) for i in lst: print(i[0], i[1]) # 字典 # dc = {} # for i in range(n): # line = input().split() # key = line[0] # value = int(line[1]) # dc.update({key:value}) # dc = sorted(dc.items(), key = lambda x : x[1], reverse = style) # for i in dc: # print(i[0], i[1])