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

Oprea Mihai
Oprea Mihai
5,592 Points

disemvowel

In my Pycharm it works but here it gives me this error

disemvowel.py
def disemvowel(word):
    #word=word.lower()
    #print (word)
    word=list(word)
    vocals=['a','e','i','o','u']

    for w in word:
        if w.lower() in vocals:
            word.remove(w)
        else:
            continue


    return"".join(word)

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! My guess here is that you haven't tested a data set that includes two vowels together. When I send "Treehouse" into your disemvowel function, I get back "Trhuse". Note that this still contains vowels. Remember, that when you use remove you are changing the indexing of the thing you're iterating over. This is causing some checks to be skipped entirely. Try either iterating over a copy of the string and mutating the original or vice versa and iterate over the original and mutate the copy.

Hope this helps! :sparkles:

Oprea Mihai
Oprea Mihai
5,592 Points

I still have error althou I redone it : def disemvowel(word): word=list(word) word_c=[] vocals=['a','e','i','o','u'] for w in word : if w.lower() in vocals: word.remove(w) else: word_c.append(w) return"".join(word_c)