Discuss / Python / 慢悠鱼

慢悠鱼

Topic source

#1 Created at ... [Delete] [Delete and Lock User]
from collections.abc import Iterable
def findMinAndMax(L):
    if isinstance(L,Iterable):
        
        if L:
            a = L[0]
            b = L[0]
            for i in L:
                a = max(a, i)
                b = min(b, i)
            return(b, a)
        else :
            return(None, None)

TIM

#2 Created at ... [Delete] [Delete and Lock User]
# 请使用迭代查找一个list中最小和最大值,并返回一个tuple:
def findMinAndMax(L):
	if L:
		min = L[0]
		max = L[0]		
		for i in L:
			if  isinstance(i,(int,float)):
				if i < min:
					min = i
				if i > max:
					max = i
			else:
				print(f'遇到非整数数据:{i},是否要处理')
		return (min,max)
	else:
		return (None,None)

#L=[]
L=[7,1,3,9,-5,'3',10.0]
print(findMinAndMax(L))

  • 1

Reply