

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to display all second lowest grade student name from nested list
Suppose we have the names and grades for each student in a nested list we have to display the names of any students having the second lowest grade. If there are more than one students with the second lowest grade, reorder these in an alphabetical order and print each name on a new line.
So, if the input is like students = [['Amal',37],['Bimal',37],['Tarun',36],['Akash',41],['Himadri',39]], then the output will be Amal, Bimal both have second least score 37, they are placed in alphabetic order.
To solve this, we will follow these steps −
- min_mark := minimum of scores for all x in students
- students := a list of students x for all x in students if score of > min_mark
- min2_mark := minimum of scores for all x in students
- students := sort the list [with names of x for all x in students if score of x is same as
- min2_mark]
- for each x in students, do
- display x
Example
Let us see the following implementation to get better understanding
def solve(students): min_mark = min(x[1] for x in students) students = [x for x in students if x[1] > min_mark] min2_mark = min(x[1] for x in students) students = sorted([x[0] for x in students if x[1] == min2_mark]) for x in students: print(x) students = [['Amal',37],['Bimal',37],['Tarun',36],['Akash',41],['Himadri',39]] solve(students)
Input
[['Amal',37],['Bimal',37],['Tarun',36],['Akash',41],['Himadri',39]]
Output
Amal Bimal
- Related Questions & Answers
- Python program to Flatten Nested List to Tuple List
- Program to create grade calculator in Python
- Python program to get all pairwise combinations from a list
- Golang Program to read the marks of subjects and display the Grade
- Python program to find Largest, Smallest, Second Largest, and Second Smallest in a List?
- Python Program to Flatten a Nested List using Recursion
- C++ program to store student roll and name using map STL
- Python Program to Display all the Nodes in a Linked List using Recursion
- Python - Convert List to custom overlapping nested list
- Python program to find the second largest number in a list
- Python program to sort a list of tuples by second Item
- Change the column name from a MySQL table with Student record?
- Nested list comprehension in python
- Python Program to get all unique keys from a List of Dictionaries
- Python - Convert given list into nested list
Advertisements