min

Return the smallest item from one iterable or the smallest of two or more arguments. key can compute the value used for ordering; ties keep the first item encountered.

Syntax

min(iterable, /, *, key=None) | min(iterable, /, *, default, key=None) | min(arg1, arg2, /, *args, key=None)

Parameters

NameDescription
iterableString | list | tuple | dict
Single iterable input. Dictionaries compare keys.
Depends on overload · Positional only
No default
argsAny
Additional positional values when passing two or more arguments.
Depends on overload · Variadic
No default
defaultAny
Value returned when the single iterable is empty. Only valid with one iterable argument.
Depends on overload · Keyword only
Default: -
keyCallable?
One-argument callable used to compute comparison keys.
Optional · Keyword only
Default: None

Returns

Any — The original smallest item, or default when an empty iterable is provided with default=.

Example

# Pick the lowest score, with a safe empty-list fallback
best = min([0.9, 0.7, 0.85])
fallback = min([], default="none")
closest = min([12, -5, 7], key=lambda value: abs(value))
text(str(closest))