Discuss / Python / 交作业

交作业

Topic source

#请使用迭代查找一个list中最小和最大值,并返回一个tuple:

def findMinAndMax(L): if L==[]: return (None, None) else: max = L[0] min = L[0] for x in L: if max < x: max = x if min > x: min = x return (max, min)

print(findMinAndMax([2,3,9,4,0,-1,11,7,8,10]))


  • 1

Reply