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

Thananjaya Chakravarthy
Thananjaya Chakravarthy
4,672 Points

how to remove vowels?

i have also tried with the for loop and if loop... but cannot ablt to get the output... can any one help me out with this one?

disemvowel.py
def disemvowel(word):
    word=list(word)
    #ele=["a","e","i","o","u"]
    #ala=["A","E","I","O","U"]
    for n in word:
        n.remove("a")
        n.remove("e")
        n.remove("i")
        n.remove("o")
        n.remove("u")
        n.remove("A")
        n.remove("E")
        n.remove("I")
        n.remove("O")
        n.remove("U")
return n

1 Answer

Here's a way I thought of...

def disemvowel(word):
    result = ''
    for letter in word:
        if letter.lower() not in 'aeiou':
            result += letter
    return result

All I'm doing here is I'm going through every letter in the string and checking to see if it's not a vowel. If it's not a vowel, we will append the letter to the result. Finally we return the result.

I hope this helps :grin:

Happy C0D1NG! :tada:

:dizzy: ~Alex :dizzy: