Discuss / Python / 不使用内置函数,仅使用迭代

不使用内置函数,仅使用迭代

Topic source

新军

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

def findMinAndMax(L):

    if L == []: return (None, None)

    __min = __max = L[0]  # 用第一个元素初始化

    for l in L:

        if l < __min:

            __min = l

        if l > __max:

            __max = l

    return (__min, __max)


  • 1

Reply