Discuss / Python / 练习

练习

Topic source

#1 Created at ... [Delete] [Delete and Lock User]

def find_min_max(lst):

    if not lst:

        return None

    # 初始化最小值和最大值为列表的第一个元素

    min_val = max_val = lst[0]

    for num in lst:

        if num < min_val:

            min_val = num

        elif num > max_val:

            max_val = num

    return min_val, max_val


  • 1

Reply