![]() |
VOOZH | about |
Given a list of numbers, the task is to find the smallest element in that list.
For example:
li= [8, 3, 1, 9, 5] -> Smallest number = 1
li = [10, 25, 7, 30, 2] -> Smallest number = 2
Let’s explore different methods to find smallest number in a list.
min() function takes an iterable (like a list, tuple etc.) and returns the smallest value.
1
We can also find the smallest number in a list using a loop (for loop). This method is useful for understanding how the comparison process works step by step.
1
Explanation:
Another way to find the smallest number in a list is by sorting it. Once sorted in ascending order, the smallest number will be at the beginning of the list.
1
Explanation: