I'm trying to program something that will filter all the vowels out of a string of text and I'm not sure why my function doesn't work. Here's my code
def anti_vowel(text):
letters = text.split() #make a list of all the letters in the string
index = 0 #for del
for x in letters:
if x == "a" or x == "A" or x == "u" or x == "U" or x == "i" or x == "I" or x == "o" or x == "O" or x == "e" or x == "E":
del letters[index]
index += 1 #to make the if-clause work
return "".join(letters) #turn the edited list into a string
While iterating over letters the if-clause should be activated when the object in letters is a vowel right? so it should delete that object. But what am I doing wrong?
filterdel letters[index]. The list is getting smaller and smaller, and when you doindex += 1you are actually skipping over an element(which was moved because of the delete).