>>> mylist = ['bunnies', 'apples', 'animals', 'fruit', 'amsterdam']
>>> for x in mylist:
print '--------------'
print x
if x[0] == 'a':
print "Removing ",x
mylist.remove(x)
--------------
bunnies
--------------
apples
Removing apples
--------------
fruit
--------------
amsterdam
Removing amsterdam
>>> print mylist
['bunnies', 'animals', 'fruit']
The output should be bunnies and fruit, animals should have been removed because it starts with an a...
I'm very confused why this isn't working, but I'm assuming that it has something to do with looping through a list while removing parts of it... Does anybody have a clearer answer for this?