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

Alejandro Byrne
Alejandro Byrne
2,562 Points

Need answer...

Sorry, rarely do I just straight up ask for an answer but this challenge has been bugging me. I've been on it for about 3 days now, and I've asked for a few hints but still can't get the hang of it. If someone could explain to me how I can complete this challenge, that would be amazing. Thanks

disemvowel.py
def disemvowel(word):
    word = list(word)
    vowls = ['a', 'A', 'e', 'E', 'o', 'O', 'i', 'I', 'u', 'U']
    counter = word.length
    while counter < :
        for item in word:
            if item is in vowls:
                word.remove(item)
            else:
                continue
    return word
Alexander Køpke
Alexander Køpke
5,065 Points

needed 30 minutes to get this as it is a long time ago I learn python. I'll try to explain what I did. My first thought was to use a regex. To use this you need to import re at the very top. Inside the function I use the findall method from re and then I pass in the regex extracting only consonants.

Now the findall method returns a list but the challenge asks for a string to be returned, so I needed to join that list before returning it.

Below I will try to rewrite the code I used but I encourage you to search for the findall method and joining lists before you read it. If you can solve it on your own that is best but even if you just try and fail and then read this code you will learn a lot!

Ok so now I will write the code that worked for me. I have to do this from memory. Hopefully it is correct.

import re
def disemvowel(word):
    word = re.findall(r'[^aeiouAEIOU]', word)
    return ''.join(word)

1 Answer

Ok... I have seen you ask this question on this quiz many times.

How about I give you pseudo program of this? It might help :)

define disemvowel(word) {

Set up a result variable that starts with a blank string

For each letter in the word {

    if the letter ISN'T a vowel {
        Concatenate the letter onto the result variable
    }

}

Return the result variable

}

Actually, this is basically the whole program. You don't need to write anything other than what's in this pseudo code.

Try to solve this on your own; If you can't solve it still, I can provide the solution along with a step-by-step explanation.

I hope this helps :grin:

~Alex

Alejandro Byrne
Alejandro Byrne
2,562 Points

Yes, I know that. But I don't know how to do if the letter isn't a vowel. I did for item in word, then I didn't know how to do if the item is in the vowel list. So I'm basically asking for a solution with an explanation.

Let's give you an example. To see if the variable x (pretend it exists, and is a single letter) is a vowel, we can do:

x in 'aeiou'