transformation
max()
Returns the largest item in an iterable or the largest of two or more arguments. Supports a key function for custom comparison.
max(iterable, *, key=None, default=...) | max(arg1, arg2, *args, *, key=None) Parameters
| Parameter | Purpose |
|---|---|
| key | Function extracting a comparison key |
| default | Value returned when iterable is empty (else ValueError) |
Examples
max([3, 1, 4, 1, 5]) Returns 5
max([{'n': 1}, {'n': 3}], key=lambda d: d['n']) Returns {'n': 3}
max('hello') Returns 'o' (highest codepoint)
Gotcha
On ties, returns the first equal-key element encountered (stable). Empty iterable without default raises ValueError.
Related built-ins
min()
Returns the smallest item in an iterable or the smallest 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.