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

Blake Fleisher
Blake Fleisher
2,848 Points

Function will not delete vowels...

I'm new to programming and am trying to figure out what's wrong with my code. This function will not delete a vowel. I've seen multiple solutions to this in the Community section, but I'm curious if my original code can be salvaged. Thanks!

disemvowel.py
def disemvowel(word):
    return word
    vowels = ["a", "e", "i", "o", "u"]
    try:
        for vowels in word.lower():
            del vowels
    except ValueError:
        pass





# make the word lower case
# remove the vowels -- try excelpt value error

1 Answer

Mathew Tran
PLUS
Mathew Tran
Courses Plus Student 10,205 Points

Hello Blake,

Your return is at the top of your function, it will return immediately before doing the other lines of code.

You will want to return when you are done processing the variable.

As for modifying your variable and getting it returned, you might want to start off with smaller steps.

Try removing looping through your word and removing all 'a's

I'd recommend looking into the built in Python string.replace method to remove the vowels, here is a reference link: Stack Overflow

Be careful that strings in python are immutable, meaning they cannot be changed. But the variables of those strings can be reassigned!

For example:

name = "Blake"
name.replace("l","r") #=> returns "Brake" but does not modify the "Blake" string
name = name.replace("l","r") # name variable is now Brake!

Matt.