Python Forum
How to find the second lowest element in the list?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to find the second lowest element in the list?
#1
I have a list of students and I have to print the names of students who have scored second lowest.

students = [['Harry', 37.21], ['Berry', 37.21], ['Tina', 37.2], ['Akriti', 41], ['Harsh', 39]]

The lowest grade of belongs to Tina. The second lowest grade of belongs to both Harry and Berry, so we order their names alphabetically and print each name on a new line.

I am extremely new to python so I have coded as below -

 studList = []
for i in range(int(input())):
  name = input()
  score = float(input())
  studList.append([name,score])
  
studList = sorted(studList, key = lambda x: x[1], reverse = True)

print(studList)  
I have done till the point that I now have a sorted list but now I am not sure I do I extract the second lowest scorer's names.
Reply


Messages In This Thread
How to find the second lowest element in the list? - by Anonymous - May-31-2022, 12:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  removing one list element without using its index paul18fr 7 1,089 Feb-22-2025, 07:59 PM
Last Post: DeaD_EyE
  question about changing the string value of a list element jacksfrustration 4 2,056 Feb-08-2025, 07:43 AM
Last Post: jacksfrustration
  extract an element of a list into a string alexs 5 3,513 Aug-30-2024, 09:24 PM
Last Post: alexs
  element in list detection problem jacksfrustration 5 1,819 Apr-11-2024, 05:44 PM
Last Post: deanhystad
  list in dicitonary element problem jacksfrustration 3 1,592 Oct-14-2023, 03:37 PM
Last Post: deanhystad
  Program to find Mode of a list PythonBoy 6 2,445 Sep-12-2023, 09:31 AM
Last Post: PythonBoy
  find random numbers that are = to the first 2 number of a list. Frankduc 23 7,028 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  compare and find the nearest element ? mr_gentle_sausage 4 2,005 Jan-15-2023, 07:11 AM
Last Post: DPaul
  Find (each) element from a list in a file tester_V 3 2,172 Nov-15-2022, 08:40 PM
Last Post: tester_V
  Сheck if an element from a list is in another list that contains a namedtuple elnk 8 3,344 Oct-26-2022, 04:03 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020