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

Hara Gopal K
PLUS
Hara Gopal K
Courses Plus Student 10,027 Points

disemvowel

was wondering why this isn't working

disemvowel.py
def disemvowel(word):
    word = list(word)
    vowels = ["a", "e", "i", "o", "u"] 
    try:
        for letter in word:
            if letter in [v.upper() for v in vowels] or letter in vowels:
                word.remove(letter)
    except ValueError:
        pass
    word = ''.join(word)
    return word

1 Answer

You are over-thinking this challenge.

You are trying to do a lot of complicated stuff, but really you don't need to do so much.

This is my pseudo-code to give you an idea of what to do:

For each item in the parameter:
    If the item lowercased isn't in the list "a", "e", "i", "o", and "u", then:
        Add the item to the result
Return the result

This isn't valid Python code, but it might give you an idea of how to tackle this problem.

I hope this helps :grin:

Happy C0D1NG! :tada:

:dizzy: ~Alex :dizzy:

Hara Gopal K
Hara Gopal K
Courses Plus Student 10,027 Points

thank you Alex...i guess I should start thinking in reverse...i was anchored to the word remove.....i feel like removing the pro tag on my gravatar :D...don't know who gave me that...

You can also accomplish this task with remove, too!

For example:

word = "A string with lot of vowels"

word_as_list = list(word)
vowels = list('aeiouAEIOU')
for vowel in vowels:
    try:
        word_as_list.remove(vowel)
    except ValueError:
        pass
disvoweled_word = ''.join(word_as_list)