Next / Previous / Contents / TCC Help System / NM Tech homepage

20.27. min(): Smallest element of an iterable

Given an iterable S containing at least one element, max(S) returns the largest element of S.

>>> min('blimey')
'b'
>>> min ( [-505, -575, -144, -288] )
-575

You may also pass multiple arguments, and the min() function will return the smallest.

>>> min(-505, -575, -144, -288)
-575

If you would like to use a different function to define the ordering, specify that function as a keyword argument key=f, where f is a function that takes one argument and returns a value suitable for comparisons. In this example, we want to order the values based on their inverse.

>>> def rev(x):
...     return -x
... 
>>> min(-505, -575, -144, -288, key=rev)
-144