Frequently Asked Python Program 19:Find 2nd Largest Number in a List

preview_player
Показать описание
Topic : Find 2nd Largest Number in a List

#########################
Udemy Courses:
#########################

Manual Testing+Agile with Jira Tool
************************************

Selenium with Java+Cucumber
********************************

Selenium with Python & PyTest
********************************

Selenium with python using Robot framework
****************************************

API Testing(Postman, RestAssured & SoapUI)
*****************************************

Web & API Automation using Cypress with Javascript
********************************************

Playwright with Javascript
**************************

Jmeter-Performance Testing
************************

SDET Essencials(Full Stack QA)
*************************

Appium-Mobile Automation Testing
************************************

Java Collections
*****************

Python Programming
*********************

Cucumber BDD Framework
***************************

Protractor with Javascript
***************************

####################################
Youtube Playlists:
####################################

Manual Testing & Agile
***********************

SQL
*************************

linux & Shell Scripting
**********************

Java
**********************

Selenium With Java+Cucumber
********************************

Python
********************************

Selenium With Python,Pytest&Behave
***************************************

Selenium With Python Using Robert Framework
(Web&API Testing)
*************************************************

API Testing (Postman,SoapUi,&Rest Assured)
**********************************************

Mobile App Testing Appium
****************************

Performance Testing Jmeter
*******************************

Maven,Jenkins,Git,Github,CI/CD
*******************************

SQL,DB Testing&ETL,Bigdata
*******************************

JavaScript Based Automation Tools
********************************

Selector Hub Tools
********************

GraphQL
******************

Cypress API Testing
********************

Cypress Web Testing
**********************

Playwright with Javascipt
**************************

#PythonProgramming
#ListManipulation
#SecondLargestNumber
#CodingChallenge
#ProgrammingTips
#PythonTips
#Algorithm
#DataStructures
#CodeSnippet
#TechHelp
#CodingCommunity
#LearnPython
#PythonLearners
#ProgrammingProblems
#CodingSolutions
#PythonFunctions
#PythonArrays
#AlgorithmDesign
#ProblemSolving
#CodingInPython
#ProgrammingLogic
#PythonDevelopment
#CodeExamples
#ProgrammingQueries
#PythonTricks
#TechLearning
#CodingExploration
#SoftwareDevelopment
#CodeDebugging
#PythonSupport
#PythonHelp
#Programming101
#CSConcepts
#CodeEfficiency
#PythonCommunity
#ProgrammingFundamentals
#CodeOptimization
#DebuggingSkills
#CodingGuidance
#PythonProblemSolving
#AlgorithmicThinking
#PythonPuzzles
#CodingWisdom
#ProgrammingJourney
#CodeMastery
#PythonAlgorithms
#CodingSkills
#LogicalThinking
#PythonChallenge
#CodeBreaker
Рекомендации по теме
Комментарии
Автор

Hi, I don't understand why do we need to convert the list in to set in 2nd method.
I will work without converting as well. please find below:

list = [11, 22, 3, 4, 55]

list.sort()
print(list)
list.remove(max(list))
print(list[-1])

ajaymangera
Автор

and what if the max elemnt is present two times in the list

lokeshnegi
Автор

Your video is very good and helpful. But what should we do in case of tuple?

aasthaporwal
Автор

Write Python program for finding the second largest element in an array A of size n using Tournament Method. Please give solutions

arunawaghmare
Автор

Why does it doesn't work when we have input of [50, 100, 50] and also [10, 400, 56, 26, 245] while getting these input from user. Here it produces output of 100 & 26 which was wrong in this case. Can someone help me in this case?

vasanthakumara
Автор

What if the list has repeating elements? i.e the largest number ocurrs twice? What then? There's no getting the second largest in that scenario

fernandoraphael
Автор

How to find the instances of second largest number

shanthisharmila
Автор

it is still working fine if I am not converting it to set
mylist=[12, 11, 54, 56, 98, 99]
mylist.remove(max(mylist))
print(max(mylist))

mohitsgit
Автор

your first approach is not reliable, what if the number is repeated twice?

Anirbansinha
Автор

Please find second largest without using in built function

obbinenireddy
Автор

SIR HOW TO FIND LARGEST NUMBER WITHOUT USING SORT() I HAVE A LIST THAT I CANNOT CHANGE POSITION OF ANY ELEMENT

GamerBoy-feey
Автор

Both the ways you told will fail. In the first way, max elem could be more then once and in second way there could be only one elem in the array/ list.

lakshayrohilla
Автор

arr = [5, 8, 1, 4, 7, 0]

def adding(arr, i, min, max, second_max):
if i >= len(arr):
return min, max, second_max
if arr[i] > max:
max = arr[i]
if arr[i] < min:
min = arr[i]
if arr[i] > second_max and arr[i] < max:
second_max = arr[i]
return adding(arr, i+1, min, max, second_max)
print(adding(arr, 0, arr[0], arr[0], arr[0]))

kvelez
Автор

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
Автор

no one tells to do this easy method in an interview

coolgirlsharu