Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to print second largest number in python

list1 = [10, 20, 4, 45, 99]
 
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))
      
 Output:-     
      
Second highest number is :  45
Comment

PREVIOUS NEXT
Code Example
Python :: doing some math in python 
Python :: whitespace delimiter python 
Python :: python transpose 
Python :: python list pop equivalent 
Python :: pandas sort by list 
Python :: firestore search query flutter 
Python :: Example 1: Reset Index & Drop Old Index pandas 
Python :: get sum of 2d array python 
Python :: Requested runtime (Python-3.7.6) is not available for this stack (heroku-20). 
Python :: count function in python 
Python :: python code to add element in list 
Python :: /n in python 
Python :: python move files 
Python :: dijkstra algorithm 
Python :: signup 
Python :: range(n,n) python 
Python :: flask echo server 
Python :: download pdf file python 
Python :: punto1 
Python :: eastvale roblox python 
Python :: random.randint(0 1) 
Python :: Paraphrasing text with transformers library 
Python :: Pipeline_parameters 
Python :: python quickly goto line in file 
Python :: list devices python 3 
Python :: how to output varibles in python 
Python :: How to know position on Kivy 
Python :: run pine script in python 
Python :: Encapsulation in Python using public members 
Python :: python method name 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =