Discuss / Python / homework

homework

Topic source

gitKong

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

为啥大家都不判断类型?list可以存放多种类型的数据的

def findMinAndMax(L):
    if L == None or len(L) <= 0 or not isinstance(L, Iterable):
        return None,None
    min = max = L[0]
    if len(L) == 1 and isinstance(min, (int,float)):
        return min, max
    for item in L:
        if not isinstance(item, (int,float)):
            raise TypeError('Error Type Compare')
        min = item if item < min else min
        max = item if item > max else max
    return min,max

  • 1

Reply