Skip to main content

How to Find the Smallest Item in a List in Python with min()

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

The fastest lap, the lowest price, the coldest night: min() looks at the values you give it and hands back the smallest one. This guide finds the fastest of three lap times on Python 3.15.2.

Syntax​

Syntax
<smallest> = min(<items>)
<smallest> = min(<first>, <second>)
PartWhat it means
<items>A list, or another group of values, to look through
<first>, <second>Two or more separate values, instead of one list
<smallest>The smallest of them

The Python documentation says min will "Return the smallest item in an iterable or the smallest of two or more arguments." An iterable is anything Python can go through item by item, such as a list.

The Example​

A runner's three laps took 62.4, 59.8 and 61.1 seconds. The fastest lap is the one with the smallest time, and the script prints it. Then it prints the smaller of two separate numbers, 8 and 5.

Prerequisites​

  • uv and Python 3. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with uv init.

Step 1: Write the Script​

laps.py
laps = [62.4, 59.8, 61.1]

print(min(laps))
print(min(8, 5))

The laps.py script in a macOS-style code window: a laps list of 62.4, 59.8 and 61.1, then prints of min(laps) and min(8, 5).

Step 2: Run It​

Terminal
uv run python laps.py
Output
59.8
5

The terminal after uv run python laps.py: 59.8, then 5.

59.8 is the smallest of the three times, so the second lap was the fastest. min(8, 5) compared its two values and gave the smaller one, 5. The command works unchanged in PowerShell.

Common Mistakes​

MistakeWhat happensDo this instead
Passing an empty listmin([]) raised ValueError: min() iterable argument is emptyGive a value to use when the list is empty: min([], default=0.0) gave 0.0
Passing a single numbermin(5) raised TypeError: 'int' object is not iterablePut it in a list, or pass two or more values
Mixing text and numbersmin([62.4, "59.8", 61.1]) raised TypeError: '<' not supported between instances of 'str' and 'float'Turn every item into a number first
Comparing numbers stored as textmin(["9", "24", "100"]) gave '100', because text is compared character by characterCompare them as numbers: min(["9", "24", "100"], key=int) gave '9'

FAQ​

Which lap was the fastest?​

Ask the list where the smallest value is. laps.index(min(laps)) gave 1. Positions start at 0, so add one for the lap number: laps.index(min(laps)) + 1 gave 2.

How do I get the smallest and the largest together?​

Call both functions. min(laps), max(laps) gave (59.8, 62.4).

How do I find the number closest to zero?​

Pass key=abs, so min compares the sizes of the numbers without their signs. min([-5, -2, 9], key=abs) gave -2. Without the key, min([-5, -2, -9]) gave -9: the smallest number, which is the one furthest below zero.

How do I find the shortest word in a list?​

Pass key=len. min(["pear", "apple", "fig"], key=len) gave 'fig'. When two items are equally short you get the first one: min(["pear", "plum", "apple"], key=len) gave 'pear'. The documentation says: "If multiple items are minimal, the function returns the first one encountered."

What does min() do with a dictionary?​

It compares the keys. With times = {"ana": 62.4, "ben": 59.8, "cy": 61.1}, min(times) gave 'ana', the first key in alphabetical order. For the smallest value, use min(times.values()), which gave 59.8. For the key that holds the smallest value, min(times, key=times.get) gave 'ben'.

Conclusion​

min(laps) went through the three lap times and gave 59.8, and min(8, 5) gave 5. Give min one list or several separate values, and add default when the list can be empty.

Additional Resources​

  • min() — the function, with key and default.
  • Comparisons — which values can be compared with each other.