+ 1

Please help me with an explanation, regarding the answer to this code

https://code.sololearn.com/c1oJ3SvzP0tV/?ref=app

31st Aug 2020, 3:53 PM
Orefo Somtochukwu Chukwudi
4 Answers
+ 2
1) step n=1 A[n]=A[1]=0 # output [1,0,3,4,1] 2) step n=0 A[0]=0 # output [0,0,3,4,1] 3) step n=3 A[3]=0 #output [0,0,3,0,1] 4) step n=0 5) step n=1 #Answer => [0,0,3,0,1]
31st Aug 2020, 4:17 PM
Muhammadamin
Muhammadamin - avatar
+ 2
In all cases and for each iteration n will not have the values 2 and 4 so first value of n not altered are 3 and 1 . n has the value 1 then 0 then 3 then 1 so no A[3] and no A[4] that will keep their initial values
31st Aug 2020, 6:00 PM
HBhZ_C
HBhZ_C - avatar
+ 1
#Run this code and see how there changing.. A=[1,2,3,4,1] for n in A: print(n, " ",A[n]) A[n]=0 print(A) #If not clear, give a reply......
31st Aug 2020, 4:15 PM
Jayakrishna 🇼🇳
+ 1
Put 1,2,.... One by one in A[n] in place of n It will be clear to you.
31st Aug 2020, 4:18 PM
Divya Mohan
Divya Mohan - avatar