Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.


+4 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

lambda arguments: expression


double = lambda x: x * 2

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 (8 points)