In this article, we will learn about the solution and approach to solve the given problem statement.
Problem statement
Given list input, we need to find the largest numbers in the given list .
Here we will discuss two approaches
- Using sorting techniques
- Using built-in max() function
Approach 1 − Using built-in sort() function
Example
list1 = [18, 65, 78, 89, 90] list1.sort() # main print("Largest element is:", list1[-1])
Output
Largest element is: 90
Approach 2 − Using built-in max() function
Example
list1 = [18, 65, 78, 89, 90] # main print("Largest element is:",max(list1))
Output
Largest element is: 90
Conclusion
In this article, we learnt about the approach to find largest number in a list.