-1
Could someone help me with a light? I can do the recursive function to find the lowest value in a list, and the highest value separately. But a function returning the two together I cannot.
The exercise would be: Write a function, called minmax, that takes a list and returns a TUPLE containing the minimum element and the maximum element of the list. Its function must be recursive.
Do not use the Python "max" or "min" command over the list. EXAMPLES:
minmax([1,2,3]) = (1, 3)
minmax([49, 1, 6, 10]) = (1, 49)
My code:
def minmax(lista):
if(len(lista) == 0):
raise ValueError('Cannot find the maximum of an empty list.')
if len(lista) == 1:
return (lista[0], lista[0])
else:
maxValue = minmax(lista[1:])
Did you even try returning the two values? What was the result obtained?
– Woss
he returns Valueerror('Cannot find the Maximum of an Empty list.')
– Isabella Picirillo
So put the code to the question and we’ll see what we can do.
– Woss
All right, I got it!
– Isabella Picirillo
could do the Sort first and then take the first and last value
– tomasantunes