8. expected a character buffer object?



Python throws the error "Oops, try again. Does your anti_vowel function take exactly one argument (a string)? Your code threw a "expected a character buffer object" error."

I expected the code to get parsed through, and all vowels assigned to the vowel variable that are in the function parameter text. Then, I expected the vowels to be replaced with empty strings.

def anti_vowel(text):
    for char in text:
        vowel = char in 'aeiouAEIOU'
    text.replace(vowel, "")
    return text


True and False are not characters, but boolean primitives. That is what is being loaded into vowel.

Now consider, since replace() is greedy and replaces all occurances of the target character, we don't have to iterate the text, just the vowels.

def anti_vowel(text):
    for vowel in "aeiouAEIOU":
        text = text.replace(vowel, "")
    return text

test = "A quick brown fox jumps over the lazy dog"
print anti_vowel(test)    #  qck brwn fx jmps vr th lzy dg


Thank you! Your help is much appreciated!