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

huyen nguyen
huyen nguyen
850 Points

Help me with my code

what's missing in my code

def disemvowel(word):
    z=["a", "e", "i", "o", "u"]
    for i in word_list:
        if i in z:
            new= word_list.remove(i)
        return str(new)

2 Answers

Hi there!

I just answered a question very similar to this.

Can you check it out here? Can't work out why my disemvowel function won't work

huyen nguyen
huyen nguyen
850 Points

I tried to copy and paste your code but it didn't work. How weird!

Did you read the other answers?

Here's the passing code:

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

As the other comments show below, my disemvowel function forgot to check both uppercase and lowercase letters. Read the comments below and you'll see :smile:

huyen nguyen
huyen nguyen
850 Points

Hi Alexander, Why don't we need a 'return' command following if command? can we write return result+=letter, instead of adding 'return result' at the last line?

Actually, we can't. This is the most simple form I can think of (unless you count list comprehensions). :smile: