8. expected a character buffer object?


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/2?curriculum_id=4f89dab3d788890003000096#

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


#2

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

#3

Thank you! Your help is much appreciated!