Help struggling in understanding! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Help struggling in understanding!

Can someone help me with understanding this problem ?! It’d be much appreciated <3 What is the output of this code? def mul (nums): return (nums*2) nums=[2,4,6,8,10] result=list(map(mul,nums)) print(result[2])

17th May 2022, 2:51 AM
Jafar Aamir
Jafar Aamir - avatar
2 Answers
+ 2
the code is multiplying every element with 2 to get a new list: 4,8,12,16,20 now you are printing result[2] which is 12 (as the index starts from 0), try changing it to 3 and you will get 16
17th May 2022, 3:07 AM
JOKER
JOKER - avatar
+ 4
Jafar Aamir I thought your code with comments might help explain https://code.sololearn.com/c55439n2UYX7/?ref=app
17th May 2022, 3:09 AM
Rik Wittkopp
Rik Wittkopp - avatar