Python 3 Script to Find Second Largest Element in an Array or List Using Max() Method Full Tutorial For Beginners

Python 3 Script to Find Second Largest Element in an Array or List Using Max() Method Full Tutorial For Beginners

 

Welcome folks today in this blog post we will be finding second largest element in an array or list using the max() method in python. All the full source code of the application is shown below.

 

 

Get Started

 

 

In order to get started we need to create an app.py file and copy paste the following code

 

app.py

 

# 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))

 

See also  Python 3 WxPython Question Yes or No Message Dialog or Modal GUI Desktop App Full Project For Beginners

Now if you execute the above python script by typing the below command as shown below

 

python app.py

 

 

Leave a Reply