Exercise 12
Using the sort () method, write an algorithm in python as a function which takes as parameter a list L of numbers and which returns the couple (min, max) formed by the minimum and the maximum of the list.
Solution
def minMax(L):
# sorting the liste
L.sort()
return (L[0] , L[-1])
# Exemple
L = [41, 19 , 5 , 21 ,7 , 11]
print(minMax(L)) # the out put is: (5, 41)
Younes Derfoufi
my-courses.net
my-courses.net