Hi everybody! Why the output of this code is 42 ? | Sololearn: Learn to code for FREE!

+13

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='')

6/1/2019 9:22:55 PM

Harimamy Ravalohery

5 Answers

New Answer

+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; 😊

+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