8.anti_vowel


#1


Oops, try again. Your function fails on anti_vowel("Hey look Words!"). It returns "None" when it should return "Hy lk Wrds!".


def anti_vowel(text):
    text=list()
    
    for l in text:
        if l in "aeiouAEIOU":
            text.remove(l)
            return "".join(text)
        else:
            return text


#2

Hi,

text=list()

This makes text an empty list, did you mean

text=list(text)

?

If a return statement is reached inside of a for loop the loop exits, so you will have to move the return statement outside of the loop.

Also iterating over a list your are changing can have unexpected consequences. It's better to iterate over one list and removing items from a copy of it or alternatively, iterate over the text string and append all none-vowels to an empty list.


#3

omg, it totally worked! Thanks!


#4

I have tried this:
def anti_vowel(text):
text = list(text)
texts = text
answer = ""
for l in texts:
if l in "aeiouAEIOU":
text.remove(l)

for i in text:
    answer += i
return answer

anti_vowel("Hey look Words!")

But it dosesn't work. What's wrong?


#5

You are looping over the same list you are removing items from. I think that's the problem. What error do you get?


#6

It says onIy only returns Hy Lk Words! Notice the O in words


#7

Try changing this

texts = text

to

texts = text[:]

I think otherwise texts just points to the text variable instead of beeing a new copy of it.


#9

def anti_vowel(text):
    vowels = ["a","A","e","E","i","I","o","O","u","U"]
    result = text
    for i in vowels:
        if i in result:
            result = result.replace(i,"")
    return result

print anti_vowel("Who let the dogs out?")

#10

Hey guys,
this is my code, can't figure out the issue.

def anti_vowel(text):
----for c in text:
--------if c not in "aeiouAEIOU":
----------- print c,
----return c


#11

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