I am new to Python and experimenting with lists
I am using Python 3.2.3 (default, Oct 19 2012, 20:13:42), [GCC 4.6.3] on linux2
Here is my samplecode
>>> l=[1,2,3,4,5,6]
>>> for i in l:
... l.pop(0)
... print(l)
...
I would expect the following output
1
[2, 3, 4, 5, 6]
2
[3, 4, 5, 6]
3
[4, 5, 6]
4
[5, 6]
5
[6]
6
[]
Instead I am getting this
1
[2, 3, 4, 5, 6]
2
[3, 4, 5, 6]
3
[4, 5, 6]
The for-loop stops iterating after 3 turns. Can somebody explain why?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…