+ 1

Someone please explain how

A=[1,2,3,4,1] for n in A: A[n]=0 print(A)

1st Jan 2019, 9:39 AM
Sona Mohan
Sona Mohan - avatar
5 Réponses
+ 6
It steps like this. A = [1, 2, 3, 4, 1] #1 n = A[0] -> 1 A[n] = 0 A = [1, 0, 3, 4, 1] #2 n = A[1] -> 0 A[0] = 0 A = [0, 0, 3, 4, 1] #3 n = A[2] -> 3 A[3] = 0 A = [0, 0, 3, 0, 1] #4 n = A[3] -> 0 A[0] = 0 A = [0, 0, 3, 0, 1] #5 n = A[4] -> 1 A[1] = 0 A = [0, 0, 3, 0, 1] So the result is [0, 0, 3, 0, 1]
1st Jan 2019, 9:55 AM
ShortCode
+ 4
Thanks ShortCode I'll delete to avoid confusion.
1st Jan 2019, 10:05 AM
Louis
Louis - avatar
+ 3
Louis I thought he is asking about a question in a challenge.
1st Jan 2019, 10:02 AM
ShortCode
+ 1
Louis ...ShortCode... Yess..this question was in the challenge..and i didnt understand how it works... Now..i get it..thanks a lot .. :)
1st Jan 2019, 10:07 AM
Sona Mohan
Sona Mohan - avatar