思路和max函数是一样的,不过是反过来的,遇到更小的就赋值给最小值
#实现min
def my_min(seq):
min_value = None
if not isinstance(seq,(list,tuple)):
return min_value
if len(seq) == 0:
return max_value
min_value = seq[0]
for item in seq:
if not isinstance(item,(float,int)):
continue
if item < min_value:
min_value = item
return min_value
if __name__ == "__main__":
lst = [1,2,'6',3,4,5]
print(my_min(lst))
lst2 = [8,2,3,4,5,'8',8]
lst2 = tuple(lst2)
print(my_min(lst2))