# Python program to find second largest
# number in a list
# list of numbers
list1 = [10, 20, 4, 45, 99]
# new_list is a set of list1
new_list = set(list1)
# removing the largest element from temp list
new_list.remove(max(new_list))
# elements in original list are not changed
# print(list1)
print(max(new_list))
# Python program to find second largest
# number in a list
# list of numbers - length of
# list should be at least 2
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]
elif mx == secondmax and
secondmax != list1[i]:
secondmax = list1[i]
print("Second highest number is : ",
str(secondmax))
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]
elif mx == secondmax and
secondmax != list1[i]:
secondmax = list1[i]
print("Second highest number is : ",
str(secondmax))
# Python program to find second largest
# number in a list
# list of numbers - length of
# list should be at least 2
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))