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

bryonlarrance
bryonlarrance
16,414 Points

Any suggestions on making this drier and getting it to pass? Thanks!!

Any suggestions on making this drier and getting it to pass? Thanks!!

disemvowel.py
vowels = ('a','e','i','o','u')

def disemvowel(word):
    word_list = list(word.lower())
    for letter in word_list:
        if letter in vowels:
            word_list.remove(letter)
        else:
            continue

    word = str(''.join(word_list))
    return word

disemvowel('pirate')

3 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

continue is the default, so you don't need that else at all. You could just return the ''.join() bit instead of making it into a variable. You don't technically need the list. You could just assemble a new string from any characters that aren't vowels (and then return that string).

But, as far as passing goes, do the instructions say to lowercase the word?

bryonlarrance
bryonlarrance
16,414 Points

Thanks for the response and for your work with the classes. I am really having a great time!!

bryonlarrance
bryonlarrance
16,414 Points

new code

vowels = ('a','e','i','o','u','A','E','I','O','U')

def disemvowel(word): word_list = list(word) for letter in word_list: if letter in vowels: word_list.remove(letter) return str(''.join(word_list))

If I remove the word_list how do I get .remove to work without getting an AttributeError?

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

You don't because you can't use .remove() on a string. If you use a string, instead of a list, you have to do an additive action instead. Make an empty string, then add characters onto it if they're not a vowel.

my_string = 'a1b2'
output = ''

for character in my_string:
    if character in '12':
        output += character

This is just an example, it isn't a solution to the code challenge :)