We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Basic Data Types
- Nested Lists
- Discussions
Nested Lists
Nested Lists
Sort by
recency
|
4230 Discussions
|
Please Login in order to post a comment
if name == 'main':
defined a record list
defined a score list
input methods
appending in the lists created
getting the second lowest value by converting to set
name list
if name == 'main': python_students=[] sc=[] for _ in range(int(input())): name = input() score = float(input()) python_students.append(list((name,score))) sc.append(score)
Read the number of students
n = int(input())
Initialize an empty list to store the student data
students = []
Read the student names and grades
for _ in range(n): name = input() grade = float(input()) students.append([name, grade])
Extract the grades from the list of students
grades = [student[1] for student in students]
Find the lowest grade
lowest_grade = min(grades)
Find the second lowest grade by filtering out the lowest grade
second_lowest_grade = min(grade for grade in grades if grade != lowest_grade)
Find the names of students who have 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 the names of students with the second lowest grade
for student in second_lowest_students: print(student)