Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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: