Basically lambda function is anonymous function - a function without a name
Syntax:
lambda arguments: expression
Example:
double = lambda x: x * 2
print(double(5))
//10
we usually use lambda function as an argument to a higher-order function (a function that takes in other functions as arguments)
my_list = [1, 5, 4, 6, 8, 11, 3, 12]
new_list = list(map(lambda x: x * 2 , my_list))
is shorter and cleaner than:
def doubleMap (x):
return x * 2
new_list = list(map(doubleMap, my_list))