Lambda Practice
sum = lambda x, y : x + y
sum(3,4)
# in this example T represents temperature, C celsius and F fahrenheit.
def fahrenheit(T): # function to calculate fahrenheit
return ((float(9)/5)*T + 32)
def celsius(T): # function to calculate celsius
return (float(5)/9)*(T-32)
temperatures = (36.5, 37, 37.5, 38, 39) # a list called temperatures
F = map(fahrenheit, temperatures) # the map function takes the two variables for fahrenheit and sores them in F
C = map(celsius, F)
temperatures_in_fahrenheit = list(map(fahrenheit, temperatures)) # then make a list of all the calculations
temperatures_in_celsius = list(map(celsius, temperatures_in_fahrenheit))
print(temperatures_in_fahrenheit) # print the list
temperatures_in_celsius
# in this example lambda is used instead of functions
C = [39.2, 36.5, 37.3, 38, 37.8]
F = list(map(lambda x: (float(9)/5)*x + 32, C))
print(F)
C = list(map(lambda x: (float(5)/9)*(x-32), F))
print(C)
a = [1, 2, 3, 4]
b = [17, 12, 11, 10]
c = [-1, -4, 5, 9]
list(map(lambda x, y : x+y, a, b))
list(map(lambda x, y, z : x+y+z, a, b, c))
list(map(lambda x, y, z : 2.5*x + 2*y - z, a, b, c))
a = [1, 2, 3]
b = [17, 12, 11, 10]
c = [-1, -4, 5, 9]
list(map(lambda x, y, z : 2.5*x + 2*y - z, a, b, c))