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

disemvowel

Hi Guys!

just keeps running an error. Please let me know if you can figure this one out!

Thanks!

disemvowel.py
word = input("Give me a word to disemvowel\n>")

def disemvowel(word):

    vowels = ["A", "E", "I", "O", "U"]
    letter = list(word)

    for letter in word:

        if letter in vowels:

            word.remove(letter)

        else:
            continue 

    return word

disemvowel(word)

1 Answer

Stuart Wright
Stuart Wright
41,120 Points

The first thing to note is that the challenge only asks you for the function. It doesn't ask you to ask the user to input a word, or call the function. Adding things like this that the challenge doesn't ask you to do can sometimes cause it to fail, although it can be good for testing purposes when running the code either in workspaces or locally.

You also need to make sure that your vowels variable contains both upper and lower case vowels as the challenge asks.

You have then attempted to iterate over the word and remove elements from it as you go. This is bad practice because it can result in elements being skipped. Imagine that your program checks the 2nd letter in the word, finds that it's a vowel, then removes it. The letter which was 3rd becomes the new 2nd letter, so when the loop skips ahead to the new 3rd letter, the original 3rd letter never gets checked.

It would be better to create a new blank list or string, and add non-vowels to this new list or string as you loop over the original work.

I'd recommend giving that a try and let me know if you encounter any more errors.