
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
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 Articles
- Python program to Flatten Nested List to Tuple List
- Program to create grade calculator in Python
- Python Program to Flatten a Nested List using Recursion
- Python Program to Display all the Nodes in a Linked List using Recursion
- 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 - Convert List to custom overlapping nested list
- Python Program to get all unique keys from a List of Dictionaries
- Write a program in Python to print the ‘A’ grade students’ names from a DataFrame
- Python program to find the second largest number in a list
- Python program to sort a list of tuples by second Item
- Python How to copy a nested list
- Python program to find all close matches of input string from a list
- Python - Convert given list into nested list

Advertisements