Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+3 votes

I found it in "Reserved Words" in the book at the top of page 32, but I haven't seen much about it. If anybody knows that would be helpful.

asked in CSC201 Spring 2021 by (8 points)

1 Answer

+3 votes

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))
answered by (2.2k points)
...