2. Lambda functions in Python


double = lambda x: x * 2
print(double(5))
myfun = lambda m: m*5
print(myfun(10))
x = lambda m,n:m*n;
print(x(2,4))
y ="lambda function"
(lambda x : print(y))(x)
print(y)
my_list = [1, 5, 4, 6, 8, 11, 3, 12]

new_list = list(filter(lambda x: (x%2 == 0) , my_list))
print(new_list)
my_list = [1, 5, 4, 6, 8, 11, 3, 12]

new_list = list(map(lambda x: x * 2 , my_list))

print(new_list)
# Program to double each item in a list using reduce()

from functools import reduce
seq = [1,2,3,4,5]
product = reduce (lambda x, y: x*y, seq)
print(product)

Post a Comment

0 Comments