Anti vowel!


#1

def anti_vowel(text):
    for i in text:
        if (i == "A" or i == "E" or i == "I" or i == "O" or i == "U" or i == "a" or i == "e" or i == "i" or i == "o" or i == "u"):
            del(text[i])
    else:
        return text

why this code is working ??


#2

if you add a function call the console shows the following error:

TypeError: 'str' object does not support item deletion

what does this mean? string are immutable in python, they can't be altered, so letters can't be deleted or removed from a string.

del (and remove) are a tricky way to solve this problem, because of index shift.

I recommend adding/appending constants to a new list/string.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.