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

Prisca Egbua
Prisca Egbua
1,167 Points

I'm trying to create a function disemvowel that can be used to delete vowel letter from a word.

it keeps saying that the function disemvowel can't be found, I've tried other options but same response. Can someone please check my code and help with this problem. Thanks

disemvowel.py
def disemvowel(word):
    word = input("type any letter to disemvowel: ")
    return word.lower()
    vowel = ['a','e','i','o','u']
    for letter in word:
        if letter == vowel:
            word.remove(letter)
        else:
            return letter
    print(word) 
disemvowel(word)
Daniel Escobar
Daniel Escobar
2,580 Points

theres's no need for print, as the challenge is asking for return. Also, you don't need the else statement. This problem is simpler than what we sees it as. I was stuck on this challenge for 3 weeks. At the end I realized that it was me who was not reading the instructions. Good luck!

Prisca Egbua
Prisca Egbua
1,167 Points

it still says can't find my function, just don't know why

3 Answers

First off, when you return anything from a function, the rest of the function will not run, instead of returning the word on line 3, simply reset word to be the lowercased word. The same for the else statement, it is not even needed. Finally, it is asked to RETURN the word at the END, not PRINT the word. And another finally, you are passing a word into a function, you DO NOT need to have an input overwriting the word passed in. I hope this helps

Daniel Escobar
Daniel Escobar
2,580 Points

not sure if this works, but I made some adjustments to your code. I truly hope it works my dear friend.

def disemvowel(word):
    word = input("type any letter to disemvowel: ")
    word2 =  list(word.lower())
    vowel = ['a','e','i','o','u', 'A', 'E', 'I', 'O', 'U']
    for letter in word2:
        if letter in vowel:
            word2.remove(letter)

    return ''.join(word2)

Be wary, you are overwriting your word passed in with the input statement.

Prisca Egbua
Prisca Egbua
1,167 Points

Thanks you. This is my code so far but it has a bug which I have not been able to fix. I state this bug in the comment. Please any more suggestion? thanks

""" the bug is that when more than one vowel appear consequently in a word, it picks the first and skip the second vowel """ def disemvowel(word): word = word.lower() print(word) word=list(word) vowel = ['a','e','i','o','u'] for letter in word: for sound in vowel: if letter == sound: word.remove(letter) print(vowel) word = "".join(word) print(word)