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

Ben Hedgepeth
seal-mask
.a{fill-rule:evenodd;}techdegree
Ben Hedgepeth
Python Web Development Techdegree Student 10,287 Points

Disemvowel challenge help

I'm uncertain why my code is not passing this challenge. Guidance as to what must be fixed is appreciated.

disemvowel.py
def disemvowel(word):

    word_characters = list(word)
    vowels = ['A', 'a', 'E', 'e', 'I', 'i', 'O', 'o', 'U', 'u']

    for character in word_characters:
        if character in vowels:
            word_characters.remove(character)
        else:
             continue


    return ''.join(word_characters)
Ben Hedgepeth
seal-mask
.a{fill-rule:evenodd;}techdegree
Ben Hedgepeth
Python Web Development Techdegree Student 10,287 Points

I believe I've figured out the issue. When removing a letter that happens to be a vowel, it shifts characters towards the front of the list while I'm iterating towards the back.

1 Answer

You're right -- your code only removes the first instance of each vowel it finds.

Try this out!

def disemvowel(word):
    word_characters = list(word)
    vowels = ['A', 'a', 'E', 'e', 'I', 'i', 'O', 'o', 'U', 'u']

    word_characters = [letter for letter in word_characters if letter not in vowels]

    return ''.join(word_characters)