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

Idan shami
Idan shami
13,251 Points

help please

I don't know what to do in this challenge..... please help

disemvowel.py
def disemvowel(word):
    for letter in word:
        if letter == ("a", "e", "i", "o", "u").lower():
            letter.remove
    return word

3 Answers

Ari Misha
Ari Misha
19,323 Points

Hiya Idan! You are doing great. But your logic is tad bit wrong. Lets break it down, shall we? Whats given to us? We have a function named "disemvowel" which takes an argument which is a "word" , made of string of alphabets. We have a list of vowels , lower as well as upper cased. What needs to be returned? We need to remove all vowels from the "word" that was passed in , and return the same word at the end of the function but withour vowels. So yeah to sum it all, here is how your code should look like:

def disemvowel(word):
    vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
    new_string = ""
    for i in word:
        if not i in vowels:
            new_string += i
    return new_string
Idan shami
Idan shami
13,251 Points

I don't understand what new_string do.... it leaves a blank string instead of the vowel? and one more question. is there another way to use instead of: if not?

Thanks a lot!

Ari Misha
Ari Misha
19,323 Points

Hiya again! I'll just walk you through the code. I created a empty string "new_string" and i have a list of vowels containing "lower" as well as "upper" vowels. Now , i looped through the "word" argument , and for every alphabet in "word" argument, which doesnt belong to "vowels" list , i added it to the "new_list" and returned the new list. In simple words, for every alphabet that doesnt belong to "vowels" list but does belong to the argument "word", gets added to the empty string. I hope it helped. (:

Idan shami
Idan shami
13,251 Points

Ok.... O.o I don't know if I understood it completely, but still, it helped a lot.... thanks (: and if you don't mind, if there is any way that we can replace the word not after the if, with something else? sorry for the drilling ^-^ have a good day (:

Ari Misha
Ari Misha
19,323 Points

Well yeah you could do that, like not use "not" in the "if" condition. How about you try it without "not" conditional in "if" and paste the code here. Maybe we both can review and make the code better? And No worries! Always happy to help (: