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

can anyone help me understand what i am doing wrong and give me the correction and what the computer interprets it as

def anti_vowel(text):
    for i in vowels:
        for c in text:
            if c != i:
                return consonants


def anti_vowel(text):
    vowels = list("AEIOUaeiou") #A for/in loop only works on lists, this splits it into one, each entry 1 character long
    text = list(text) #See above
    for c in text:
    	truey = 'true' # You need this because of how the loops are ordered
    	for i in vowels:
            if c == i:
                truey = 'false' # You had the loops the wrong way, so, if the character didn't match the first vowel, it appended to the consonants list
    	if truey == 'true':
    return consonants #Your return statement was returning as soon as it found a character that worked


This work fine:

def anti_vowel(text):
for i in text:
if i !="a" and i!="e" and i!="i" and i!="o" and i!="u" and i!="A" and i!="E" and i!="I" and i!="O" and i!="U":
return a


Thanks for the help:grinning:


This variable should be defined inside the function so it is local.

Iterate only over the text, not the vowels. We need to find repeats.

    result = []
    for i in text:
        if i not in vowels:
    return ''.join(result)


A post was split to a new topic: Can we use this code? answer is none


def anti_vowel(test):

for char in test:
    if char != 'a' and char!='e' and char!='i' and char!='o' and char!='u' and char != 'A' and char!='E' and char!='I' and char!='O' and char!='U':
return ''.join(test1)


Do you not find that to be overly repetitive and verbose? That code is a demonstration of how not to code, and while it may work, it proves nothing except refusal to use tools readily at hand.

Non-repetitive, concise code:

    result = []
    for i in text:
        if i not in "aeiouAEIOU":
    return ''.join(result)

We can further refactor the above into a single return statement:

def anti_vowel(x):
    return ''.join([i for i in x if i not in 'aeiouAEIOU'])


This is the best one. Thanks


Best example code in this thread, very nice.


this is so nice! thank you


Hi i was just checking your code and I realized your return indent was a little off. It should not be within your for loop otherwise it will print each letter with one other letter concatenated on a new line which throws a error. But other than that excellent code!


Was waiting for someone to spot that. Good eye! Will fix it, now.


def anti_vowel(text):
result = ""

for c in text:
    if c not in "aeiouAEIOU":
        result += c

return result

print anti_vowel("Hey You!")


Like your code a lot. I used lambda/filter but it's probably less pythonic.


This is a great code, I was struggling with the length and repetition of it all. I saw your condensed code and it helped me understand it.



A post was split to a new topic: Is there a reason we define an empty string