I have some easy code:
a = [1,2,3,4,3,3,5]
for letter in a:
print (letter)
if letter == 3:
a.remove(letter)
print ('a=',a)
The output shows:
1
2
3
3
5
a= [1, 2, 4, 3, 5]
I expect to see:
1
2
3
4
3
3
5
a=[1,2,4,5]
What is happening? It seems in the loop that the "a" list is also being updated simultaneously. How can I fix the for loop to get the expected output?