visited_cities = ["New York", "Shanghai", "Munich", "Toyko",
"Dubai", "Mexico City", "São Paulo", "Hyderabad"]
for city in visited_cities:
if len(city) > 5:
visited_cities.remove(city)
else:
continue
print(visited_cities)
I confirmed that 'Shanghai' is recognized as length greater than 5 using print instead of remove. So why is 'Shanghai' and 'São Paulo' remaining on list while 'New York' 'Munich' 'Mexico City' and 'Hyderabad' are removed?