I am learning the list and list assignments and using while and for loops with lists. I wrote the following code just to test my understanding.
I=[1,4, 7, 6, 7,8,9]
IU=I
while IU !=[]:
print ('I: ',I)
print('IU :' ,IU)
for i in I:
print(i)
if i*i<=36:
IU.remove(i)
print(IU)
if i>=9:
break
This gives the following output:
I: [1, 4, 7, 6, 7, 8, 9]
IU : [1, 4, 7, 6, 7, 8, 9]
1
[4, 7, 6, 7, 8, 9]
7
6
[4, 7, 7, 8, 9]
8
9
My understanding is that it would print 4
after it removed 1
from IU
. However it is not printing 4
. Any hints on why this is happening?