Exercise 12
By using the sort() method, write an algorithm in python as a function which takes a list L of numbers as a parameter and which returns the tuple (min , max) formed from the minimum and the maximum of the list.
Solution
1 2 3 4 5 6 7 8 |
def minMax(L): # sort the list L.sort() return (L[0] , L[-1]) # Example L = [37, 59, 11, 3, 47, 22 , 6] print(minMax(L)) # the output is: (3, 59) |
Younes Derfoufi
CRMEF OUJDA
1 thought on “Solution Exercise 12: maximum and minimum of a Python list”