Second Largest Number From List | Coding Questions in Python | Python Interview Questions

preview_player
Показать описание
Second Largest Number From List | Coding Questions in Python | Python Interview Questions
This video is part of python coding questions and answers. In this video,i have explained one more Coding Question with proper explanation.

1) Infosys Coding Question
2) Logical Questions in Python
3) Infosys Interview Questions and Answers

source code :-

About Python Tutorial:- python for beginners-Go from Zero to Hero in python.This tutorial includes python programming videos from basics to advanced

More tutorials:-

About codeyug :-
Codeyug provides tutorials for building your programming skills.Here,you will learn various programming languages,computer science,web development with free of cost.

SHARE | SUBSCRIBE | LIKE
-- - - - - - - - - - - - - - - - - -Thanks for watching this video - - - - - - - - - - - - - - - - - -- -
Our social links:-
creator:-
$ -shantanu kejkar -$

#python #python3 #programming #codeyug #tutorial #beginners #coding
Рекомендации по теме
Комментарии
Автор

Humesha ke trha ya vedio bhi bht Help full rha thank you sir ❤❤❤bht acha explain kiy apne

python
Автор

3:01 Hi. You didn't explain why it needs to add [0] next to nums.

Cloudxxx
Автор

Best code for this problem is given below,

y=[ 2, 3, 6, 6, 5 ]
y.sort(reverse=True)
for i in y:
if (i<max(y)):
print(i)
break

propagandabuster
Автор

def find_max_min_number(array):


 

    largest_num=array[0]

    second_largest_num=0


 

    for i in array:

        if i > largest_num:

            largest_num=i


 

    print("Largest number is:", largest_num)


 

    for i in array:

        if i > second_largest_num and i !=largest_num:

            second_largest_num=i

    print("Second Largest Number:=", second_largest_num)

   

array_range=int(input("Enter Array Range:"))

loop_counter=0


 

nums=[]

for i in range(array_range):

    loop_counter+=1

    print(loop_counter, end=" ")

    element=int(input("Enter Array Element:"))

    nums.append(element)


 

array=[]

for i in nums:

    if i not in array:

        array.append(i)


 

print('Remove All Dublicates:', array)

find_max_min_number(array)

niravparekh
Автор

nums = [159, 78, 91, 29, 159, 99]
f_lar = nums[0]
s_lar = nums[1]
for i in range(len(nums)):
if nums[i]>f_lar:
f_lar=nums[i]
for i in range(len(nums)):
if nums[i]>s_lar and nums[i]!=f_lar:
s_lar=nums[i]
print(s_lar)

afreedpasha
Автор

What if we want third largest in manual way ?

Mahesh_
Автор

its not largest number is in 0 index so largest and second largest output will be same

aparnachouhan
Автор

second_largest = nums[1] then we are getting right answer if we take second_largest as nums[0] we will get the first_largest value only

afreedpasha
Автор

in simple way
first_largest=max(nums)
second_largest=nums[0]
for i in range(len(nums)):
if nums[i]>second_largest and nums[i]!=first_largest:
second_largest=nums[i]
print(second_largest)

shanvikgowda
Автор

This code will not work for second Highest value if 0 element of the the list is the highest number Ex: lst1= [100, 45, 76, 9, 23, 37, 84, 1]

ramunagaram