Discuss / Python / 使用迭代查找的最简洁代码

使用迭代查找的最简洁代码

Topic source

遥望君山

#1 Created at ... [Delete] [Delete and Lock User]
def findMinAndMax(L):
    if not L:
        return (None, None)
    min, max = L[0], L[0]
    for i in L:
        min = i if i < min else min
        max = i if i > max else max
    return (min, max)



  • 1

Reply