+ 1

Challenge problem

Why does this code k = list(map(\ lambda x,y:x+y, list(range(100)),list(range(10)) )) print(k) Output : [0, 2,4,6,8,10,12,14,16,18] How does it really work?? Thanks 👍

6th Apr 2022, 6:45 AM
eskayML 💣
eskayML 💣 - avatar
2 Answers
+ 8
The lambda takes a value from list( range( 100 ) ) and list( range( 10 ) ) and sum each taken value up. But even though the first `list` has 100 elements, the lambda can only take 10 out of it because the second `list` only has that many elements. list( range( 100 ) ) [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ... , 99 ] list( range( 10 ) ) [ 0, 1, 2, 3, 4, 5 6, 7, 8, 9 ] Lambda took a value from each list 0 and 0 => 0 1 and 1 => 2 2 and 2 => 4 .... 9 and 9 => 18 I guess it goes like that ...
6th Apr 2022, 7:07 AM
Ipang
+ 3
Thanks Ipang
6th Apr 2022, 11:44 AM
eskayML 💣
eskayML 💣 - avatar