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

Emil Hejlesen
Emil Hejlesen
3,014 Points

hey can any one help me with removing the vowels in the python coding challenge disemvowel.py :)

i need to remove all vowels from a word

disemvowel.py
def disemvowel(word):
    list(word)
    for x in word:
        if x == "a", "e", "i", "o", "u":
            word.remove(x)

    word.join()        
    return word
Emil Hejlesen
Emil Hejlesen
3,014 Points

i have changed my code to this but it still doesnt work:

def disemvowel(word): word = list(word) for x in word: if x == "a" or x.upper() == "A": word.remove(x)

    elif x == "e" or x.upper() == "E":
        word.remove(x)
    elif x == "i" or x.upper() == "I":
        word.remove(x)

    elif x == "o" or x.upper() == "O":
        word.remove(x)

    elif x == "u" or x.upper() == "U":
        word.remove(x)

    else:
        pass

word = "".join(word)
return word

2 Answers

Kent Åsvang
Kent Åsvang
18,823 Points

Before asking questions in the treehouse-community you should try to search and see if someone else has asked the question. Then you wouldn't have to wait for an answer:)

Review of you attempt:

    def disemvowel(word):
        list(word)
        for x in word:
            if x == "a", "e", "i", "o", "u":
                word.remove(x)

        word.join()        
        return word

You have the right idea, but have made a few errors.

  1. list(word) returns the word as a list, but the return value isn't stored anywhere. should be something like: letters = list(word)

  2. if x == "a", "e", "i", "o", "u": this is invalid syntax. If you wan't to use if-statements this way, you have to make one for each letter.

Solution

    def disemvowel(word):
        """ removes the vowels from a string """
        VOWELS = list("aeiou")
        word_wo_vowels = ""

        for letter in list(word):
            if letter in VOWELS:
                pass
             else:
                word_wo_vowels += letter

        return word_wo_vowels

Hope this helped some way.

Emil Hejlesen
Emil Hejlesen
3,014 Points

hey tried again with this and it still doesn't work

Emil Hejlesen
Emil Hejlesen
3,014 Points

I fixed it now, there was an error with the code you posted it didn't take the capitalized letters but i just added them to the list and it worked, thank you :)

Kent Åsvang
Kent Åsvang
18,823 Points

Sorry about the error. I am not a paying treehouse-student so I don't have access to the challenge to see all the criteria.

Emil Hejlesen
Emil Hejlesen
3,014 Points

np thank you for the help :)

Emil Hejlesen
Emil Hejlesen
3,014 Points

Thank you for the quick answer :) i tried something similar but i didn't work i have also posted this in the comments thank you for the help, much easier to see my mistake now :)