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 (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,629 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")