Python | Find Smallest Number in List

Python’s List Object type is quite useful for storing data while dealing with Scientific Computations where large amount of data need to be processed. Anyway, in this article => I’ll discuss How to find Minimum Number from a List of Numbers in Python?

For finding minimum number out of all numbers in Python List, Any of following three approaches can be used =>

  • Using Sort Function sort() for finding Minimum Number in a List
  • Python’s built-in min() function for finding smallest number in a List
  • Using For Loop in order to find minimum number in a Python List

Let’s discuss each one of these algorithmic approaches for Finding Minimum Number in a Python List.

Approach 1 => Find Minimum Number in a Python List

  1. Define Python List
  2. Sort list in ascending order by calling sort() function on it
  3. First Element in sorted list will be smallest, access it by list_name[0]
# Python Program to Find smallest number in List

a_list = [73, 92, 294, 19, -10, -2, -67]     # Define List

a_list.sort()                                # Sort Nunbers in List in ascending order

# First element in Sorted List will be Smallest Number
print("Smallest Number in List is => ", a_list[0])

Output of Above Code

Smallest Number in List is =>  -67

Approach 2 => Find Smallest Number in a Python List

  1. Define Python List
  2. Pass list to min() function as a parameter
  3. min() function will return Smallest Number in List
# Python Program to Find smallest number in List

a_list = [763, 92, 81, 12, 14, 26, 91, -10, -23, -14]     # Define List

minimum_number = min(a_list)             # Call min() Function by passing list to it

# First element in Sorted List will be Smallest Number
print("Smallest Number in List is => ", minimum_number)

Output of Above Code

Smallest Number in List is =>  -23

Approach 3 => Finding Minimum Number out of a Python List

  1. Define Python List
  2. Assume first number in Python List to be smallest
  3. Loop over all numbers in List using for loop and compare each number with the assumed minimum number, update assumed minimum number to current iteration number if its lesser than assumed minimum number
  4. At the end of for loop return assumed minimum number variable, which now will be Smallest Number in Python List
# Python Program to Find smallest number in List

a_list = [74, 92, 28, -34, 81, -8, 19, 38, -12]     # Define List

min = a_list[0]

for i in range(len(a_list)):                # Looping over each element of List
	if a_list[i] < min:
		min = a_list[i]

print("Smallest Number in List is => ", min)

Output of Above Code

Smallest Number in List is =>  -34

Gagan

Hi, there I'm founder of ComputerScienceHub(Started this to bring useful Computer Science information just at one place). Personally I've been doing JavaScript, Python development since 2015(Been long) - Worked upon couple of Web Development Projects, Did some Data Science stuff using Python. Nowadays primarily I work as Freelance JavaScript Developer(Web Developer) and on side-by-side managing team of Computer Science specialists at ComputerScienceHub.io

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts