Anti_Vowel not catching all instances of a letter


def anti_vowel(text):
    letters = list(text)
    vowels = ["o", "O", "a", "A", "e", "E", "i", "I", "u", "U"]
    for p in letters:
        if p in vowels:
    print "".join(letters)
    return "".join(letters)

This returns "Hy lk Words!" as opposed to the expected "Hy lk wrds!"

It seems as if once the program removes the first couple of Os in "look", it disregards the ones that follow. How do I stop that happening?


This is the issue. Using .remove in a loop can result in errors since it interrupts the iteration. Better in this instance to build a new list from the non-vowels in text.

Also, since a string is iterable, we don't need a list.

    letters = []
    for p in text:
        if p not in "aeiouAEIOU":
    return "".join(letters)


One long winded way of doing it :joy:

def anti_vowel(text):
    vowelless = ""
    for letter in text:
        if ord(letter) == 97 or ord(letter) == 101 or ord(letter) == 105 or\
ord(letter) == 111 or ord(letter) == 117 or ord(letter) == 65 or \
ord(letter) == 69 or ord(letter) == 73 or ord(letter) == 79 or \
ord(letter) == 85:
            vowelless += ""
            vowelless += letter
    return vowelless


And one short-winded way...

def anti_vowel(text):
    return "".join([p for p in text if p not in "aeiouAEIOU"])
print anti_vowel("the quick brown fox jumps over a lazy dog")

# th qck brwn fx jmps vr  lzy dg


Excellent lesson to make such kind of memes, lol