- Related Questions & Answers
- Python program to find Largest, Smallest, Second Largest, and Second Smallest in a List?
- Python Program to Find the Second Largest Number in a List Using Bubble Sort
- C# program to find Largest, Smallest, Second Largest, Second Smallest in a List
- Python program to find the largest number in a list
- Python program to find largest number in a list
- Program to find second largest digit in a string using Python
- Java program to find Largest, Smallest, Second Largest, Second Smallest in an array
- Find the Second Largest Element in a Linked List in C++
- Python Program to Find the Largest Element in a Doubly Linked List
- Python program to find N largest elements from a list
- Python program to find the smallest number in a list
- Program to find the largest grouping of anagrams from a word list in Python
- Python Program for Find largest prime factor of a number
- Python program to sort a list according to the second element in sublist
- Python program to sort a list according to the second element in the sublist.

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this article, we will learn about the solution to the problem statement given below.

**Problem statement **− We are given a list, we need to display the second largest number in a list.

There are three approaches to solve the problem−

list1 = [11,22,1,2,5,67,21,32] # to get unique elements new_list = set(list1) # removing the largest element from list1 new_list.remove(max(new_list)) # now computing the max element by built-in method? print(max(new_list))

32

list1 = [11,22,1,2,5,67,21,32] # using built-in sort method list1.sort() # second last element print("Second largest element in the list is:", list1[-2])

Second largest element in the list is: 32

list1 = [11,22,1,2,5,67,21,32] #assuming max_ is equal to maximum of element at 0th and 1st index and secondmax is the minimum among them max_=max(list1[0],list1[1]) secondmax=min(list1[0],list1[1]) for i in range(2,len(list1)): # if found element is greater than max_ if list1[i]>max_: secondmax=max_ max_=list1[i] #if found element is greator than secondmax else: if list1[i]>secondmax: secondmax=list1[i] print("Second highest number is the list is : ",str(secondmax))

Second highest number is the list is : 32

In this article, we have learned about how we can find the second largest element in a list.

Advertisements