+ 3

I don't undersrand why the output is 222!!!!

I see that with the definition I get a list with three functions, I think that 012 is the output expected but it is 222!!! Why? https://code.sololearn.com/ccyPlPxCFUXL/?ref=app

1st Mar 2020, 1:17 AM
Urbo Fresco
Urbo Fresco - avatar
3 RĂ©ponses
+ 3
Thanks LDSD and Tibor Santa! The links worked to me! I got a better idea with the lambdas!
1st Mar 2020, 8:23 AM
Urbo Fresco
Urbo Fresco - avatar
+ 2
You can read about it here, which is better explained than anything I could write: https://stackoverflow.com/questions/139819/why-results-of-map-and-list-comprehension-are-different Read up so you know why this behaviour is intended. Then you can fix your lambda like this: lambda x, u=i: u*x for i in range(3)
1st Mar 2020, 4:24 AM
LDSD
LDSD - avatar
+ 2
Check this thread maybe it helps to get a better understanding. https://www.sololearn.com/Discuss/2180319/?ref=app I think this is pretty mean for a challenge question đŸ€” Really not trivial, but a good point that you have to be very careful with using lambda in comprehension.
1st Mar 2020, 4:53 AM
Tibor Santa
Tibor Santa - avatar