+ 1
How does the code works ?
https://code.sololearn.com/cgL2EC6TiiId I need help to understand how does the lambda works here. Thanks in advance.
6 Antworten
+ 3
Awww yeah. And cause you put lambda x=x.
func(x=1) you just gave it a default each time.
func(x=2) and so on. It's so messy what's the exact purpose on why you want to use this?
+ 9
The future is now thanks to science[In a break] ,
in case we only wanted to print the values, we can omit the creation and iteration of a new list of values. we can use print() function inside the comprehension:
[print(x*10) for x in range(1, 11)]
+ 3
I agree with you.Using only list comp is a better idea.
I got that from geeksforgeeks and didn't understand the way it works.
+ 2
@slick I guess I've understand. Thanks for the answer.
Yeah , I guess there's no reason to use it as we can get the same result using only list comprehension:
https://code.sololearn.com/cs2N3VEtDwsg
I got stuck with that example while learning in geeksforgeeks that's why I asked .
https://www.geeksforgeeks.org/JUMP_LINK__&&__python__&&__JUMP_LINK-lambda-anonymous-functions-filter-map-reduce/
+ 1
it creates a list of lambda functions using the range values as values for x. Why not just the list comp? Comes out with the same answer and you can actually do something with the data
0
I see so it just converts the list of value into functions as a list.
So when you print the function each function returns a value in sequence which we can get from list comprehension.
But why every function takes only one value ?
For my guess, I thought every function will return the 10-100 value as a list.
Also why I don't have to pass any argument?
I didn't understand how does lambda x=x: works.
Maybe I'm missing something.