I'm having trouble understanding how 'for loop' works in Python. I want to remove a character from a list using for loop to iterate through the list but the output is not as expected. In the following code I want to remove the character 'e':
lista = ['g', 'e', 'e', 'k', 'e','s', 'e', 'e']
for x in lista:
if x == 'e':
lista.remove(x)
print(lista)
It prints ['g', 'k', 's', 'e', 'e'] when I was expecting ['g', 'k', 's'].
Thank you.