min() is one of Python’s most essential built-in functions — it returns the smallest item in an iterable or the smallest of two or more arguments, with optional key for custom comparison and default for empty iterables. In 2026, min() remains a cornerstone in data science (finding minimum values in pandas/Polars/Dask Series, bottom-k results, threshold detection), software engineering (priority queues, validation), and algorithms (minimum spanning tree, leader election) — supporting key functions, multiple iterables, and efficient reduction with O(n) time complexity.
Here’s a complete, practical guide to using min() in Python: basic usage, key function, default handling, real-world patterns (earthquake magnitude analysis, bottom performers, time series minima), and modern best practices with type hints, performance, edge cases, and integration with NumPy/Dask/Polars/pandas/xarray.
Basic min() — smallest item in iterable or among arguments.
# From iterable
print(min([7.2, 6.8, 5.1, 8.9])) # 5.1
print(min("python")) # 'h' (lexicographically smallest)
print(min(range(100))) # 0
# Multiple arguments
print(min(42, 7, 100)) # 7
print(min(3.14, 2.718, key=int)) # 2 (key=int truncates)
# Empty iterable with default
print(min([], default=999)) # 999
key function — custom comparison (like sorted).
events = [
{'mag': 7.2, 'place': 'Japan'},
{'mag': 5.1, 'place': 'Alaska'},
{'mag': 6.8, 'place': 'Chile'}
]
# Min by magnitude
weakest = min(events, key=lambda e: e['mag'])
print(weakest['place']) # Alaska
# Min by place name length
shortest_place = min(events, key=lambda e: len(e['place']))
print(shortest_place['place']) # Chile (5 chars)
Real-world pattern: earthquake analysis — find weakest events, minimum magnitudes per group.
import pandas as pd
import polars as pl
df = pd.read_csv('earthquakes.csv')
# Pandas: weakest event
weakest_pd = df.loc[df['mag'].idxmin()]
print(f"Weakest: Mag {weakest_pd['mag']} in {weakest_pd['place']}")
# Polars: min per country
min_per_country = (
pl.from_pandas(df)
.group_by('country')
.agg(pl.col('mag').min().alias('min_mag'))
.sort('min_mag')
)
print(min_per_country.head())
# Dask: lazy min
ddf = dd.from_pandas(df, npartitions=4)
global_min = ddf['mag'].min().compute()
print(f"Global min magnitude: {global_min}")
Best practices for min() in Python & data workflows. Prefer min(iterable, key=func) — for custom ordering; use default for empty cases. Modern tip: use Polars pl.col('mag').min() — fast columnar min; Dask ddf['mag'].min().compute() for distributed. Use min() with enumerate() — min(enumerate(lst), key=lambda x: x[1]) for index of min. Add type hints — def find_min_event(events: list[dict]) -> dict. Use min(..., default=float('inf')) — safe for empty numeric iterables. Avoid min() on empty without default — raises ValueError. Use heapq.nsmallest() — for bottom-k smallest items. Use sorted(iterable)[0] — alternative but slower O(n log n). Use min() with key=operator.itemgetter('mag') — faster than lambda. Use min(df['mag']) — pandas/Polars Series min. Use ddf['mag'].min().compute() — Dask lazy min. Use np.min(arr) — NumPy array min. Use ds.min() — xarray Dataset min. Use min() in assertions — assert min(df['mag']) >= 0. Use min() in loops — early stopping with sentinel. Use min() with generator — min(gen) consumes generator. Use min() with zip() — min(zip(scores, names)) for lowest scorer. Use min() with filter() — min(filter(lambda x: x > 0, lst)). Use min() with map() — min(map(len, strings)) for shortest string.
min() finds the smallest item — in iterables or arguments, with key for custom comparison and default for empty cases. In 2026, use for minima detection, bottom-k ranking, validation, and integrate with pandas/Polars/Dask/NumPy for vectorized min operations. Master min(), and you’ll efficiently find lows and perform conditional reductions in any data or algorithmic workflow.
Next time you need the minimum value — use min(). It’s Python’s cleanest way to say: “Find the smallest one — with custom rules if needed.”