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

Noah Harness
Noah Harness
1,383 Points

I suck at programming and its making me upset

I don't know how to do this shit.

disemvowel.py
blank_word = ""
vowels = ["a", "e", "i", "o", "u"]
def disemvowel(word):
    for letter in word:
        if letter not in vowels:
            blank_word += letter
            print(blank_word)

1 Answer

Umesh Ravji
Umesh Ravji
42,361 Points

Hi Noah, you pretty much have the answer there :) You do know how to do it.

vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]  # have to include both upper and lower cases
def disemvowel(word):
    blank_word = ""  # better as a local variable inside the function
    for letter in word:
        if letter not in vowels:
            blank_word += letter
    return blank_word  # remember you want to return this, not print it out

if you want to avoid including capitals and lowercase letters in vowels, you can just check if char.lower() not in vowels:. That way, no matter what the case of char is, it'll still be in the list.