Python program to find second largest number in a list
In this tutorial, You will learn how to python program to find second largest number in a list
Step 1: Create a list with elements
Step 2: Sort the list by using sort() function
Step 3: The list is also index start with 0 same like arrays. We can pull the list ending values in by using -1, -2,-3 etc with respective. -1 means last index, -2 means second last index. The sort list with -2 index will gives second largest number in the list.
# Python program to find largest number in a list # list of numbers L = [19, 21, 25, 22, 58] # sorting the list L.sort() # printing the second last element print("Second largest number in the list is:", L[-2])
Second largest number in the list is: 25