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

Ben Thrower
Ben Thrower
1,760 Points

Disemvowel

Hi,

This code works in the editor but not on the exercise.

disemvowel.py
def disemvowel(word):
    word_list = list(word)
    vowels = ['A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u']
    for letter in word_list:
      if letter in vowels:
        try:
            del(word_list[word_list.index(letter)])
        except ValueError:
            pass
    new_word = "".join(word_list)
    return new_word

print(disemvowel("frustrating"))

1 Answer

Nader Alharbi
Nader Alharbi
2,253 Points

It says to you if you enter (PeA) you should get P But your code gave PA, your code is not 100% correct.

If you wish to delete something from a list while iterating, you probably should create a copy of the list and work on it. Or you could try to append instead of deleting.