题解 | #成绩排序# 字典键不可重复
成绩排序
https://www.nowcoder.com/practice/8e400fd9905747e4acc2aeed7240978b
while 1: try: n=int(input()) # 成绩个数 rank_way=int(input()) # 0-降序,1-升序 ''' grade={} # 字典的键不允许重复,相同键不同值,相当于更新键的值 for i in range(n): info=input().split() grade[info[0]]=int(info[1]) #print(grade) l=grade.items() grade1=sorted(l,key=lambda i:(i[1]),reverse=(1-rank_way)) for i in grade1: print(i[0],i[1]) ''' grade=[] for i in range(n): info=input().split() info1=[info[0],int(info[1])] grade.append(info1) grade.sort(key=lambda i:i[1],reverse=1-rank_way) #print(grade) for i in grade: print(i[0],i[1]) except: break