+ 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
4 Respuestas
+ 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.
+ 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)
+ 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 ☺
+ 1
thanks Maninder Singh