Program to find second largest number or element in list; In this tutorial, i am going to show you how to find second largest number from list in python.

And i will write some python program to find second largest element or number from list.

## Python Program to Find Second Largest Number From a List

- Python program to find second largest number in list using Sort() method
- Python program to find second largest number in list using function
- Python program to find second largest number in list using Max() method

### Python program to find second largest number in list using Sort() method

See the following steps to write a python program to find the second largest element or number in the list using sort() method:

- Get input length of list from user in program.
- Define empty list in program.
- Then, iterate the for loop and merge the numbers in the list.
- Use the sort method to find second largest numbers from the list.
- Print the results.

# Python program to find second largest number in a list # using sort method # make empty list list1 = [] # take input number of elements in list num = int(input("Enter number of elements in list: ")) # iterating till num to append elements in list for i in range(1, num + 1): ele = int(input("Enter elements: ")) list1.append(ele) ''' # sort the list list1.sort() # print second maximum element print("Second largest element is:", list1[-2]) ''' # print second maximum element using sorted() method print("Second largest element is:", sorted(list1)[-2])

After executing the program, the output will be:

Enter number of elements in list: 5 Enter elements: 10 Enter elements: 20 Enter elements: 4 Enter elements: 45 Enter elements: 90 Second largest element is: 45

### Python program to find second largest number in list using function

See the below given steps to write a python program to find the second largest element or number in the list using custom function and max() method:

- Take input the length of the list from user in program.
- Next, iterate the for loop and add the number in the list.
- Define function and implement logic to find second largest number from list.
- Call above define function with list.
- Print second largest number from list

# Python program to find second largest number in a list # using custom function with max method # make empty list list1 = [] # take input number of elements in list num = int(input("Enter number of elements in list: ")) # iterating till num to append elements in list for i in range(1, num + 1): ele = int(input("Enter elements: ")) list1.append(ele) mx=max(list1[0],list1[1]) secondmax=min(list1[0],list1[1]) n =len(list1) for i in range(2,n): if list1[i]>mx: secondmax=mx mx=list1[i] elif list1[i]>secondmax and \ mx != list1[i]: secondmax=list1[i] print("Second highest number is : ",\ str(secondmax))

After executing the program, the output will be:

Enter number of elements in list: 5 Enter elements: 10 Enter elements: 20 Enter elements: 4 Enter elements: 45 Enter elements: 90 Second highest number is : 45

### Python program to find second largest number in list using Max() method

See the below given steps to write a python program to find the second largest element or number in the list using max() and set() method:

- Take input the length of the list from user in program.
- Next, iterate the for loop and add the number in the list.
- Create new list with set method
- To remove first largest element from list using remove() method
- Print second largest number from list

# Python program to find second largest number in a list # using set and max method # make empty list list1 = [] # take input number of elements in list num = int(input("Enter number of elements in list: ")) # iterating till num to append elements in list for i in range(1, num + 1): ele = int(input("Enter elements: ")) list1.append(ele) # create new list using set new_list = set(list1) # delete the largest element from new list new_list.remove(max(new_list)) print("Second largest element is:", max(new_list))

After executing the program, the output will be:

Enter number of elements in list: 5 Enter elements: 10 Enter elements: 20 Enter elements: 4 Enter elements: 45 Enter elements: 90 Second highest number is : 45

## Recommended Python Tutorials

**Recommended:-**Python Program to Print Binary Numbers From 1 to N

**Recommended:-**Python Program to print Elements in a List

**Recommended:-**Python Program to Swap Characters of Given String

**Recommended:-**Swap First Two Characters in Each String in Python

**Recommended:-**Python Split String into Array of Characters

**Recommended:-**Python Program to Reverse String Using Stack

**Recommended:-**Python Insert Element at Specified Index in List

**Recommended:-**Python Program to Swap Two Elements in a List

**Recommended:-**How to Take Input List From User in Python

**Recommended:-**Python Program to Find LCM of Two Numbers

**Recommended:-**Python Add and Remove Elements From List

**Recommended:-**Python Find Difference of Two Lists

**Recommended:-**Python Program to Split Even and Odd Numbers in List

**Recommended:-**Python Program Count vowels in String

**Recommended:-**Python Program to Find HCF or GCD of Two Numbers

**Recommended:-**Python Program to find Sum of N Natural Numbers

**Recommended:-**Python Program to Find the Square Root of Number

**Recommended:-**Python Program to Check Armstrong Number

**Recommended:-**Python Program to Find Factors of a Number

**Recommended:-**Python Program for Binary Search

**Recommended:-**Python remove a character from a string

**Recommended:-**Python String to Int() and Int to String

**Recommended:-**Python Program for Linear Search

## Be First to Comment