-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNested Lists
44 lines (36 loc) · 1.05 KB
/
Nested Lists
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Print the name(s) of any student(s) having the second lowest grade in. If there are multiple students, order their names alphabetically and print each one on a new line.
Sample Input 0
5
Harry
37.21
Berry
37.21
Tina
37.2
Akriti
41
Harsh
39
Sample Output 0
Berry
Harry
_______________________________________________________________________________________
solution of this code is
n = int(input())
# Create a nested list to store student names and grades
students = []
for _ in range(n):
name = input()
grade = float(input())
students.append([name, grade])
# Find the second lowest grade
grades = sorted(set(student[1] for student in students))
second_lowest_grade = grades[1]
# Get the names of students with the second lowest grade
second_lowest_students = [student[0] for student in students if student[1] == second_lowest_grade]
# Sort the names alphabetically
second_lowest_students.sort()
# Print each name on a new line
for name in second_lowest_students:
print(name)
______________________________________________________________________________