利用Python迭代器查找最小值和最大值

如果给定一个list或tuple,我们可以通过for循环来遍历这个list或tuple,这种遍历我们称为迭代(Iteration)

#利用Python迭代器查找最小值和最大值
def findMaxandMin(l):
if l==[]:
return (none,none)
else:
min=l[0]
max=l[0]
for i in l:
if max<i:
max=i
if min>i:
min=i
return(max,min)

print(findMaxandMin([2,4,1,5])) #(5,1)
原文地址:https://www.cnblogs.com/dcx-1993/p/10316327.html