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 (Retired) Lists Redux Disemvoweled

Dee K
Dee K
17,815 Points

My code partially works.

My code appears to work for every vowel except the first one in a word. Can someone help me out with this?

def voweler(x):

    vowels = list('aeiou')
    empty_list = []
    for letter in x:
        empty_list.append(letter)          
        for vowel in vowels:
            if vowel in letter:
                empty_list.remove(vowel)

    print(''.join(empty_list))        
voweler("California, New York, Texas, Louisiana, Tennessee, Alabama, Oklahoma, Arizona")

1 Answer

John Lindsey
John Lindsey
15,641 Points

The issue is because they are capitalized and it is case sensitive. There are two ways to solve this problem. You can either add the capitalized letters to your vowels list or you can lower all the letters in x when you are comparing it to the vowels (but then use the normal letter when adding it). Also, you can do the test to see if the letter is a vowel before appending it to your list. I only changed this to make it simpler, but the rest of the code below is copied from the original post. Hope this helps. (:

def voweler(x):

    vowels = list('aeiouAEIOU')
    empty_list = []
    for letter in x:
        if letter not in vowels:
            empty_list.append(letter)

    print(''.join(empty_list))
voweler("California, New York, Texas, Louisiana, Tennessee, Alabama, Oklahoma, Arizona")


# or you could do:

def voweler2(x):

    vowels = list('aeiou')
    empty_list = []
    for letter in x:
        if letter.lower() not in vowels:
            empty_list.append(letter)

    print(''.join(empty_list))
voweler2("California, New York, Texas, Louisiana, Tennessee, Alabama, Oklahoma, Arizona")