Discuss / Python / 迭代作业3-插入代码

迭代作业3-插入代码

Topic source

煎饼果子

#1 Created at ... [Delete] [Delete and Lock User]
def find_min_and_max(L):
    if not L:
        # return (None, None)
        return None, None
    elif len(L) == 1:
        return L[0], L[0]

    max, min = None, None
    for i in L:
        if max is None and min is None:
            # 0不是None
            # None不推荐使用=
            # Python可以 max==min==None
            max = i
            min = i
            continue;
        if i > max:
            max = i
        elif i < min:
            min = i
    return min, max

  • 1

Reply