+ 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='')
5 Answers
+ 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.
+ 15
(lambda x)=nums =>
=> nums+2 =>
=> 2+[2, 0] =>
=> 2+2, 2+0 =>
=> 4 2;
sep=' ' - removes a space between 4 and 2 => 42; đ
+ 11
Some might say it's because 42 is the answer to everything but that wouldn't be the right answer.
+ 1
the reverse of this output :
nums = [2,0]
result = map(lambda x: x + 2, nums)
print(*reversed(list(result)),sep='')
- 2
BECAUSE U PROGRAMMED IT TO BE 42