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

Marie Spreitzer
Marie Spreitzer
1,268 Points

Please, someone check my code and help me figure out why it doesn't work!

I know I could have coded it in an easier way but I am still trying to figure out why it doesn't work here.

Thankssss :))

disemvowel.py
def disemvowel(word):
    list = word.split()
    for letter in list:
        while True:
            try:
                list.remove("aeiouAEIOU")
            except ValueError:
                pass
            break
    word = " ".join(list)
    return word

1 Answer

  1. When you split the list in your code, it is not returning a list of letter but a list of words.. so if you were to input "apples" as the word parameter your list variable would be ['apples'].

  2. The list.remove("aeiouAEIOU") only works if the word parameter is equal to "aeiouAEIOU"

def disemvowel(word):
    letter_list = list(word)
    vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']
    for letter in letter_list:
        if letter in vowels:
            letter_list.remove(letter)
    return ''.join(letter_list)