Anti-Vowel. Does ".del" actually work?


Getting syntax error in the line with "i.del"

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



Solved. Found solution in other post.


why even use del? It sounds like a bad idea, i would just append constants to a new list, the end. Anyway, python has good documentation, here is a link to the documentation about del

your range function is a problem, the range function requires to arguments, start and stop. text is just a string, range expects a number, so you would need to use len(), i would personally remove range altogether:

for i in text:

this will give you the letter, rather then the indexes. Saves you a of time and lines of code

you use the append function wrong, take a look:


before the . is where you want to append (list), between the brackets is what you want to append (item you append to the list)


Well I did some research and 'del' function isn't entirely bad idea IF it's used properly. But I see what you mean. There are just better ways to solve this exercise.

I found post where coder used:

no_vowels = ""
for i in text:
if not (i in 'aeiouAEIOU'):
no_vowels += i

Which I find very elegant way to make this one work .... I didn't know about "not" function.

Thanks stetim94 !


the del function is a bad idea, because if you have multiple vowels (week, beer, so on), you get index shift, which causes problems.

Not is not a function, it is a keyword. That is a elegant solution, but the purpose of this exercises are to let you do the thinking, to design the program, that is really the next step in programming


I don't mind do the thinking. Look what I came up with at first. It's the first post here. Can't believe how stupid that looks. lol

I guess I understand the lesson you trying to teach me here. Let others give you clues and hints not solutions.


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