+ 2
Why this output occur?
x=[1,2,3,4] for i in x: x.remove(i) print(x) #output=[2,4] but why can anyone explain it.
3 Respostas
+ 2
In first iteration i=1 and the x becomes x=[2,3,4].Now i moves to next index that is i=3 and 3 is removed. Now the x size is 2, next i looks for next 3rd index, it is not possible so x has 2 and 4.
+ 2
G.S.N.V. Suraj why i!=2
0
For each iteration i takes the value of next index in x. When 1 is removed the index of 2 is one(first position) but i will take the element at second position so i!=2.