+ 14

Hi everybody! Why the output of this code is 42 ?

from __future__ import print_function nums = [2,0] result = map(lambda x: x + 2, nums) print(*result, sep='')

1st Jun 2019, 9:22 PM
Harimamy Ravalohery
Harimamy Ravalohery - avatar
5 Respuestas
+ 8
Map, applies lambda on nums and adds 2 on its elements and returns the result in "result" list. * operator extracts the result elements from [4, 2] to 4 2 form. And finally print with sep='' (which means that it should concatenate parameters) outputs it to 42 form.
2nd Jun 2019, 12:10 AM
Qasem
+ 15
(lambda x)=nums => => nums+2 => => 2+[2, 0] => => 2+2, 2+0 => => 4 2; sep=' ' - removes a space between 4 and 2 => 42; 😊
1st Jun 2019, 9:35 PM
Solo
Solo - avatar
+ 11
Some might say it's because 42 is the answer to everything but that wouldn't be the right answer.
2nd Jun 2019, 12:48 AM
Sonic
Sonic - avatar
+ 1
the reverse of this output : nums = [2,0] result = map(lambda x: x + 2, nums) print(*reversed(list(result)),sep='')
2nd Jun 2019, 2:45 PM
abderrahim sallami
abderrahim sallami - avatar
- 2
BECAUSE U PROGRAMMED IT TO BE 42
3rd Jun 2019, 4:06 PM
Roj Serbest