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

Holden Glass
Holden Glass
6,077 Points

Disemvoweled is not working

I wrote this code for the challenge and it doesn't work even though it works in workspaces. Although if I put 'weeeeeeeeeeeeeeeeeeee' in for the word in workspaces is doesn't get rid of all of the e's and the first for loop only runs 22 times on that word then quits. I don't know why.

disemvowel.py
def disemvowel(word):
    vowel = ['a', 'e', 'i', 'o', 'u']
    the_word = list(word)
    for lett in the_word:
        for let in vowel:
            if lett == let:
                the_word.remove(let)
    return ('').join(the_word)

1 Answer

Torsten Lundahl
Torsten Lundahl
2,570 Points

Instead of using two loops you could use 'in' to check if lett appears inside vowels, and then remove the letter straight away.

if lett in vowel: <remove lett>

Also the join method don't need the parenthesis on the string that's used to join the sequence.

Hope that'll clear things up for you!

Holden Glass
Holden Glass
6,077 Points

Yes, thank you. I did clear things up.