Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Collections (2016, retired 2019) Lists Disemvowel

Tobias Sanden
Tobias Sanden
2,324 Points

Why do I get a Type_Error?

Trying to return the word without the vowels, but not having any success... Any advice on what could be going wrong?

def disemvowel(word):
    for letter in word:
        if letter=="A" or "E" or "I" or "O" or "U":
            word.remove (letter)
    return word

2 Answers

Brendan Whiting
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,735 Points

This is the error message I get:

TypeError: 'builtin_function_or_method' object is not iterable

So what's happening is you're trying to loop over an object which is actually a function, not a list. How did we get here?


You're not calling the function with parens (). You're just assigning the function itself to the variable word, rather than assigning the result of the function call. So then later on when you try and loop over it, it's complaining.

Cooper Runstein
Cooper Runstein
11,850 Points

You've got a few problems. First, consider this little piece of python:

variable = 7
variable == 7 or 3
variable == 6 or 3
variable == 3 or 7

At first, this code seems to be doing what you want it to, but after more testing, it should be clear that you aren't running the correct comparison. You're not actually checking if variable is equal to the second number. What you need to do is:

variable == 7 or variable == 3
variable == 3 or variable == 7
variable == 6 or variable == 3

Finally, you're trying to use a method on the string object that doesn't exist, You never actually changed word to a list, so remove isn't doing anything.