关于Python递归求列表最大值最小值

img

img

def find_mm(L):
    global depth
    
    depth += 1
    print("Into", depth, L)
    
    if len(L) == 1:
        depth -= 1
        print("return to ", depth)
        return L[0], L[0]
    if len(L) == 2:
        depth -= 1
        print("return to ", depth)
        return min(L[0], L[1]), max(L[0], L[1])
    min1, max1 = find_mm(L[0:len(L)//2])
    min2, max2 = find_mm(L[len(L)//2:len(L)])
    
    depth -= 1
    print("return to", depth)
    return min(min1, min2), max(max1, max2)
depth = 0
L = [9, 3, 1, 5,2, 0, 7, 8, 10, 2]
print(find_mm(L))