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

whats wrong with my code

on line 6, its showing me errors with tabs

def disemvowel(word):

    for letter in word:
        if letter == "a" or letter == "e" or letter =="i" or letter == "o" or letter == "u" or letter=="A" or letter == "E" or letter == "I":
        elif letter=="O" or letter =="U":

    return word

1 Answer

Steven Parker
Steven Parker
230,231 Points

I tried it and I get a different error: "NameError: name 'i' is not defined". Your strategy is unusual yet essentially sound, but to get the index you need will require some refactoring of the loop.

You should also be aware that modifying an iterable while it is controlling a loop can cause the loop to skip items. You might need to use a copy of the iterable instead.

Bonus hint: The membership operator ("in") can make your testing much more compact:

        if letter in "aeiouAEIOU":