I am new to python and programming in general and currently learning the fundamentals. In the script below I am trying to check the number of letters in each list element and delete ones with five and more letters. I am using for-loop to achieve this but an issue is occurring because of the change in the number of list elements which does not corresponds to the for-loop range considered initially. I tried to let the range vary itself but I errors are still obtained.
# -*- coding: utf-8 -*-
magicians =['alice','david','carolina']
def counter(word):
x= sum (c != ' ' for c in word)
return x
print magicians
for i in range (0,3):
magicians[i]=magicians[i].title()
print magicians
q=
Y=range (0,q)
for i in Y:
x= counter(magicians[i])
print x
if x<=5:
print 'this component will be deleted:', magicians[i]
del magicians[i]
q=q-1
Y=range (0,q)
print magicians
Thank you