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

well i need help with my disemvowel.py code

i have written my code but i am not sure how best to correct my code

def disemvowel(word):
    return word
vowel = ('a', 'e', 'i', 'o', 'u')
if vowel.lower:
    try disemvowel.remove('a', 'e', 'i', 'o', 'u')
    return word
else vowel.upper:
    disemvowel.remove('a', 'e', 'i', 'o', 'u')
    return word

1 Answer

Hi there,

I did this in a different way. But bear with me - it might help you out.

I started the method by declaring a list of vowels, just like you have. I also created a new variable, I called it output, to store the letters in I want to return after the method completes.

I then looped through the parameter, word. I used a for/in loop, like this:

for letter in word:
    # do something with letter

So, the variable letter holds each letter in word in turn as the loop iterates.

I then checked to see if the letter was not in the list of vowels. If it wasn't, add it to output That way, I'm creating a set of letters that aren't vowels. (I checked the lower case version of letter too).

Once the loop finished, I returned output.

Have a go at that - see what you think.