+ 1
Someone please explain how
A=[1,2,3,4,1] for n in A: A[n]=0 print(A)
5 ответов
+ 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]
+ 4
Thanks ShortCode I'll delete to avoid confusion.
+ 3
Louis I thought he is asking about a question in a challenge.