Python Lists – Find largest and smallest element in a list

In this post we will be creating a script that will find the largest and the smallest element within a list, lists in Python are a means to store multiple pieces of data in to a single variable. To achieve this we will be using Pythons inbuilt functions ‘min()’ and ‘max()’.

The ‘min()’ function will be used to retrieve the smallest item in an iterable.

The ‘max()’ function will be used to retrieve the largest item in an iterable.

See below our list for this example.

List=[1, 2, 3, 4, 4, 5, 5, 5, 5, 6, 7, 8, 9]

The snippet code below uses the min and max functions to retrieve the relevant items from our list.

highest = max(List)  
print(highest)

lowest = min(List)
print(lowest)

Leave a Reply