Anti Vowel


#1

I found changing the nesting on one loop makes this go from correct to incorrect, however I cannot figure out why.

This code works:

def anti_vowel(text):
    texty = []
    for i in text:
        texty.append(i)
        for i in texty:
            if i in "aeiouAEIOU":
                texty.remove(i)
    return "".join(texty)

This code does NOT:

def anti_vowel(text):
    texty = []
    for i in text:
        texty.append(i)
    for i in texty:
        if i in "aeiouAEIOU":
           texty.remove(i)
    return "".join(texty)

Can anyone explain why? It will leave the "O" in "Word" if the second code is chosen.


#2

This is how I did it :slightly_smiling:
def anti_vowel(text):
- string = ""
- for i in text:
-- if i.lower() not in "aeiou":
--- string += i
- return string
print anti_vowel("Hey look Words!")

As you can see there is no need to make list out of a string, works this simple way.
Sorry I don't get it how to get the code indented so I've added some dashes