from pprint import * sites = [[\'a\',\'b\',\'c\'],[\'d\',\'e\',\'f\'],[1,2,3]] pprint(sites) for site in sites: sites.remove(site) pprint(sites) <
from pprint import * sites = [[\'a\',\'b\',\'c\'],[\'d\',\'e\',\'f\'],[1,2,3]] pprint(sites) for site in sites: sites.remove(site) pprint(sites)
It's because you're modifying a list as you're iterating over it. You should never do that.
For something like this, you should make a copy of the list and iterate over that.
for site in sites[:]: sites.remove(site)