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

Benjamin Bradshaw
Benjamin Bradshaw
3,208 Points

I think this challenge is harder then they realize. What am i doing wrong?

I think I need to turn the entry into a list before removing the vowels. Then I need to turn it back but I am not sure I am doing that correctly. It always says "Bummer!" and doesn't give me much indication as to what I am doing wrong.

disemvowel.py
def disemvowel(word):
    vowels = ('A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u')
    word_list = list(word)

    for letter in word_list:
        if letter in vowels:
            word_list.remove(letter) 
    word = "".join(word_list)
return word

1 Answer

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

you're pretty close. first thing to see is that your return statement is not indented properly and thus is not actually a part of the function. it needs to be tabbed over once. then, your code is otherwise fine except you are looping through a list while modifying it with remove. remove removes the indicated element, then shifts remaining elements over to the left. the loop however moves on to the next element which results in skipping elements. to fix you can make a copy of the list and loop through that while modifying the original, or vice-versa.

Benjamin Bradshaw
Benjamin Bradshaw
3,208 Points

your solution makes perfect sense but I am struggling to implement it. How do I make a copy of the list and loop through it while modifying the original? It sounds simple enough but I am struggling.