(python) sorting students' grades

[Problem description]
Sort the grades of students in a class. Enter the names and grades of a class of students (the maximum number of students in a class is not more than 50) from the keyboard and save them, and then output the names and grades of the students in descending order of the students' grades. If the grades are the same, they will be sorted according to the input order.
[Input form]
Enter the names and grades of no more than 50 students in sequence from the keyboard:
enter the number of students in the class on the first line;
enter the names and grades of students separated by spaces on a separate line, where the grades of students are integers.
[Output format]
Output student names and grades in descending order of student grades, and output the name and grades of one student per line, where the name (English) occupies 15 digits and the grade occupies 5 digits, and they are aligned by default. If the results are the same, they are sorted in the order they were entered.
【Input sample】

4
aaa 50
bbb 70
ccc 65
ddd 90

【Example of output】

############ddd###90
############bbb###70
############ccc###65
############aaa###50
(Note: The "#" sign represents a space)

[Example description]
Enter the names and grades of four students, and output them in order of grades.

 

n = int(input())
#人数
my_list = []
#创建一个主列表
for i in range(n):
    j = []#创建新列表并添加到主序列表中
    my_list.append(j)#将n个列表添加到主列表里面
    for i in range(1):
        a,b=map(str,input().split(' '))
        j.append(a)
        j.append(b)     
my_list2=sorted(my_list,key=(lambda x:x[1]),reverse=True)#排序
for i in range(n):
     print("            {}   {}".format(my_list2[i][0],my_list2[i][1]))

Guess you like

Origin blog.csdn.net/qq_62315940/article/details/127994458