0

Lambda function python

Is there any way to print actual data of list in this code? https://code.sololearn.com/cuKVhSEIs5Z6/?ref=app

31st Aug 2021, 1:30 PM
Gajendra Sonare
Gajendra Sonare - avatar
2 Réponses
+ 4
Gajendra Sonare , not quite sure if this is (in principle) what you meant: ▪︎to do a calculation with a lambda and append it directly, we need to use the lambda expression itself: ▪︎the first part: (lambda x,y: x + y) we use 2 variables. the expression is in parenthesis: ▪︎x - that will get the number coming from the range ▪︎y - that will get a number that we need for tge addition ▪︎the second part is also in parenthesis and take the arguments to use: (num, 4) this is also set in parenthesis. num comes from the range lst = [] for num in range(2,7): lst.append((lambda x,y: x + y)(num, 4)) print(lst) # result = [6, 7, 8, 9, 10]
31st Aug 2021, 2:23 PM
Lothar
Lothar - avatar
0
1. Define lambda: f = lambda x: x+1 2. Use lambda: f(2)
31st Aug 2021, 1:33 PM
Lisa
Lisa - avatar