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

disemvowel.py

how do you do it?

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

    for letter in letters:
        if letter in vowels
            letters.remove(letter)



    return ''.join(letters)

1 Answer

Hi there,

I think if you remove from the letters iterable, you will start skipping elements in your for loop. If you are at element 2 and you then remove it, what was element 3 becomes element 2; so your next loop iteration will skip the original 3 and go straight to 4 (which is now at 3!). I hope that made sense!

To complete this, I created an output string and initialized it to be empty at the start of the method. I then created a list of lowercase vowels.

I looped over word. If each element (lowercased using lower()) was not in the list of vowels, I added it to the output string. At the end of the loop, I returned the output string.

I hope that helps - shout if you need more.

Steve.