transformation
min()
Returns the smallest item in an iterable or the smallest of two or more arguments. Supports a key function for custom comparison.
min(iterable, *, key=None, default=...) | min(arg1, arg2, *args, *, key=None) Parameters
| Parameter | Purpose |
|---|---|
| key | Function extracting a comparison key |
| default | Value returned when iterable is empty (else ValueError) |
Examples
min([3, 1, 4, 1, 5]) Returns 1
min(['abc', 'de'], key=len) Returns 'de'
min([], default=0) Returns 0 (no ValueError)
Gotcha
Passing an empty iterable without default raises ValueError. Mixing incomparable types (int vs str) raises TypeError.
Related built-ins
max()
Returns the largest item in an iterable or the largest of two or more arguments. Supports a key function for custom comparison.
sorted()
Returns a new sorted list from any iterable. Uses Timsort — stable, O(n log n).
sum()
Sums the items of an iterable, adding them to start. Optimized for numbers.
any()
Returns True if any element of the iterable is truthy. Short-circuits on the first truthy value.
all()
Returns True if every element of the iterable is truthy (or if the iterable is empty). Short-circuits on the first falsy value.