Use iteration to find the minimum and maximum values in a list and return a tuple:
def findMinAndMax(L): if L==[]: return None,None if len(L)==1: return L[0],L[0] min=max=L[0] for n in L[1:]: if max<n: max=n elif min>n: min = n return min,max # test if findMinAndMax([]) != (None, None): print('Test failed!') elif findMinAndMax([7]) != (7, 7): print('Test failed!') elif findMinAndMax([7, 1]) != (1, 7): print('Test failed!') elif findMinAndMax([7, 1, 3, 9, 5]) != (1, 9): print('Test failed!') else: print('Test succeeded!')