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 task

Hi guys,

I have been struggling with this task below. It runs in pycharm but does not work on the Treehouse console/tool.

Please help.

def disemvowel(word): vowels = ['a','e','i','o','u'] * len(word) word = list(word) for x in vowels: if x in word: word.remove(x) word = ''.join(word) return word

disemvowel.py
def disemvowel(word):
    vowels = ['a','e','i','o','u'] * len(word)
    word = list(word)
    for x in vowels:
        if x in word:
            word.remove(x)
    word = ''.join(word)
    return word

4 Answers

Also I've just realized that since your for loop is iterating through the list of vowels, it will only remove the first instance if a certain vowel in the word, if the word has 2 of the same vowels it will not catch the 2nd one. To avoid this you should try iterating through the provided word instead of the list of vowels.

def disemvowel(word):
    vowels = ['a','e','i','o','u']
    output = list(word)
    for i in word:
        if i.lower() in vowels:
            output.remove(i)
    output = ''.join(output)
    return output

This is how I would do it, you might ask why I introduced the new output variable and not just turn WORD into a list of WORD but in that case while I was iterating through the list and I deleted a vowel, the number of indexes in word would go down and the iterator would skip a letter.

First off, I don't know why you're multiplying your list of vowels by the length of the word, you should remove that, also you are only testing for lower case vowels, not upper case.

Thanks Susannah for responding.

The reason why I multiplied the list of vowels by the length of the word is to accommodate for instances where a vowel occurs more than once. When I remove the '* len(word)' then words such as 'school' returns as 'schol'.

When using the list_name.lower() or .upper() functions it doesn't return the original casing of the word.

So am stuck with these two issues. Is there perhaps another method to solve these errors of mine?