assume we have a list , and I want to make it clear one by one. look at this code :
#code1
>>> x=[9,0,8,1,7,2,5]
>>> for i in x :
x.remove(i)
>>> x
[0, 1, 2]
at last x are not clear . why ? and
#code2:
>>> for i in x :
x.remove(x[0])
>>> x
[7, 2, 5]
this code is like code1. compare the two codes by code3, why they are not act like this one:
#code3:
>>> while x:
x.remove(x[0])
>>> x
[]
I have another question about for/while loop , when python run :
for i in x
or
while x
does all of x content are in memory/RAM ? if yes, what I can do when x are too big , for better performance?