How do you find min and max without using min and max function [duplicate]

One way would be using a for loop:

def get_min_max(numbers):
    if not all([type(number) in [int, float] for number in numbers]):
        raise TypeError('All items in numbers must be int or float.')

    min = None
    max = None
    for number in numbers:
        min = number if min is None or number < min else min
        max = number if max is None or number > max else max

    return min, max

Leave a Comment