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


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/2?curriculum_id=4f89dab3d788890003000096


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
        else:
            i.append(no_vowels)
    
    print no_vowels
    return no_vowels

anti_vowel("Mark")


#2

Solved. Found solution in other post.


#3

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:

list.append(item)

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


#4

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 !


#5

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


#6

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.


#7

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