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

Nathaniel Bell
Nathaniel Bell
6,020 Points

This code works in the python shell, returning the word without vowels, upper or lower case. Why does it fail the check?

I think I have a working solution, and I have verified in the python shell tat it returns the desired output...can anyone point out my mistake as to why it is not passing the check? Thanks!

disemvowel.py
def disemvowel(word):
    vowels = ['a','e','i','o','u']
    word_list = list(word)
    for letter in word_list:
        if letter.lower() in vowels:
            word_list.remove(letter)
            word = ''.join(word_list)
    return word

1 Answer

James J. McCombie
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
James J. McCombie
Python Web Development Techdegree Graduate 21,199 Points

Hi,

you function does not produce the correct output, it's always safe to assume if strings are involved in these challenges the tests are seemed to me to always try some slant on 'Treehouse' directing my testing to look at cases of this really helped me out and your code produces 'trEhus' from 'treEhOuse' when I tested it.

This is maybe due to you modifying a container as you iterate over it, which is generally not a good idea, perhaps you could refactor to iterate over the word_list, and build a new list as you do, excluding the vowels.

the placement of the join statement also seems off.