Explain
i want get all items in for loops using list and method pop(default)
given the follow code:
text = ['a','b','c']
for i in text:
print(i)
it returns all items in list
a b c
Ploblem
but when i tried this code
text = ['a','b','c']
for i in text:
z=text.pop()
print(z)
print('remains text :',text)
it returns :
c b remains text : ['a']
item 'a' still left in text[ ]
why?? the Explain code prints all items but this does not
i think it has to be loop for 3 times and get all items
but only 2 times working
i want know why can't loop all counts
it has to happens 3 times but only 2 times
thx.
sorry for re-asking
so i get it 'text' is mutable so when loop execute 'text' it will be changed but
i dont get the mechanism why ['a'] remains
can you explain about the process?
pop():
['a','b','c'] > ['a','b'] > ['a']
i mean.... it changes but i think still does't matter to print c b a
left 1 items but it works in for()
this is exatly what i want
text = ['a']
for i in text:
z=text.pop()
print(z)
print('remains text :',text)
result :
a remains text : []
for more explain
text = ['a','b','c']
for i in text:
print('text',text)
z=text.pop()
print('pop:',z)
print('remains text :',text)
`
text ['a', 'b', 'c']
pop: c
remains text : ['a', 'b']
text ['a', 'b']
pop: b
remains text : ['a']
`
left 1 but not working!!
sorry that i'm fool :)