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

uday kiran
uday kiran
3,222 Points

My code is not working

def disemvowel(word): wli=[] wli.extend(word.lower()) vov=["a", "e", "i", "o","u"] word=""

for i in wli:
    if i in vov:
        continue
    else:
        word+=i
return word
disemvowel.py
def disemvowel(word):
    wli=[]
    wli.extend(word.lower())
    vov=["a", "e", "i", "o","u"]
    word=""

    for i in wli:
        if i in vov:
            continue
        else:
            word+=i
    return word

2 Answers

Ryan S
Ryan S
27,276 Points

Hi Uday,

Your logic works except for one thing: it doesn't account for upper case letters. When you extend "word" into the "wli" list, you are permanently changing all letters to lowercase. This is why it is not passing. Any uppercase letters that were originally passed in are now overwritten.

In order to fix this, you can move the .lower() method to your if statement, and use that to check for membership. This will preserve the original case of the letters.

def disemvowel(word):
    wli=[]
    wli.extend(word)  # Remove .lower()
    vov=["a", "e", "i", "o","u"]
    word=""

    for i in wli:
        if i.lower() in vov:  # Add .lower()
            continue
        else:
            word+=i
    return word

Hope this helps.