# To use reduce, we need to import it from # the functools library from functools import reduce myList = [-100, 30, -23, 32, 13, 100, 22, 101] #---------------------- # EXAMPLE OF MAP #---------------------- def FtoC(degreesF): return (degreesF - 32) * (5/9) def list_FtoC(tempList): # MAP applies FtoC to each element in the list # It returns a MAP object that is ITERABLE. tempMap = map(FtoC, tempList) # We transform it into a list before returning return list(tempMap) #---------------------- # EXAMPLE OF REDUCE # --------------------- def maxOfTwo(x, y): if x > y: return x else: return y def maxOfList(numList): return reduce(maxOfTwo, numList) def minOfTwo(x, y): if x > y: return y else: return x def minOfList(numList): return reduce(minOfTwo, numList) print('Temperature list in Fahrenheit : ', myList) tempList = list_FtoC(myList) print('Max temperature in Celsius : ' + '{:.{}f}'.format(maxOfList(tempList),2)) print('Min temperature in Celsius : ' + '{:.{}f}'.format(minOfList(tempList),2))