I have found this problem, while googling, but could not understand how is it happening?
a = [0, 1, 2, 3]
for a[-1] in a:
print(a[-1])
Result:
0 1 2 2
Now if I print a again:
a
[0, 1, 2, 2]
Another similar example:
let a be the original list i.e., [0,1,2,3]
Now, let's run another for loop, but like this:
for a[0] in a:
print(a[0])
This time result is :
0 1 2 3
But again printing a:
[3,1,2,3]
So, I have two questions:
1) How the original list is getting updated in both the cases?
2) What is the explanation of the result in the first case i.e., with the negative index for loop?