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
|
4608 Discussions
|
Please Login in order to post a comment
n = int(input("Enter number of Students: ")) stu_list = []
# Collecting student names and scores
for i in range(n): name = input("Student name: ") score = float(input("Score: ")) stu_list.append([name, score])
# Extracting only the scores
marks_list =[x[1] for x in stu_list]
# Finding the second lowest score
m = sorted(set(marks_list)) # Sorting unique scoresPrinting names
for name in names: print(name)
Printing names
for name in names: print(name)
Read the number of students
n = int(input())
Initialize lists to store student names and grades
students = [] grades = []
Read each student's name and grade
for _ in range(n): name = input() grade = float(input()) students.append((name, grade)) grades.append(grade)
Find the second lowest grade
sorted_grades = sorted(set(grades)) # Get unique grades and sort them second_lowest_grade = sorted_grades[1] # The second lowest grade is at index 1
Find students with the second lowest grade
second_lowest_students = [name for name, grade in students if grade == second_lowest_grade]
Sort the names alphabetically
second_lowest_students.sort()
Print each name on a new line
for student in second_lowest_students: print(student)
if name == 'main': def second_last(l): sl = max(l) for i in l: if i > min(l): if i < sl: sl = i return sl
`
if name == 'main':