+ 1

map function

i really an explanation on why these two code produce completely different results. I don't understand the steps https://code.sololearn.com/clCpeO3Wj7t1/?ref=app https://code.sololearn.com/cbWshYgyqGQU/?ref=app

28th May 2018, 10:43 AM
Doe Dare Oladimeji
Doe Dare Oladimeji - avatar
4 ответов
+ 4
Doe Dare Oladimeji remember that when parameter used in function is equal to the parameter used in map function, then map takes only one element of the list but when parameter used in function is not equal to the parameter used in map function then map take complete list as a one element and use it.
28th May 2018, 4:35 PM
Maninder $ingh
Maninder $ingh - avatar
+ 2
In your first map: # To avoid confusion, I had changed parameter of corpus i.e., *nums to num* only in map(1) def corpus(num): return num*2 # Note: here, num (parameter) is an element of nums (array i.e., [1,2]). So, the return statement returns twice of num. nums = [1,2] callosum = list(map(corpus,nums)) print(callosum) And, in your second map: def corpus(byte): return nums*2 # Note: here, nums is the array itself. So, the return statement returns [1,2], [1,2] nums = [1,2] callosum = list(map(corpus,nums)) print(callosum)
28th May 2018, 11:04 AM
777
777 - avatar
+ 1
Rahul when i ran the code after changing the parametet to "num", i got the same output as map(2); that didnt answer my question. but your explanation makes a lot of sense although not fully comprehended. thanks ☺
28th May 2018, 12:29 PM
Doe Dare Oladimeji
Doe Dare Oladimeji - avatar
+ 1
28th May 2018, 5:36 PM
Doe Dare Oladimeji
Doe Dare Oladimeji - avatar