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

Erik Nemcik
Erik Nemcik
1,569 Points

Why is this not working?

The print part is only for me to keep track of the deletion process. I know that this could probably be written in a more elegant manner but I simply can't get my head around why it does not work. Thanks.

disemvowel.py
def disemvowel(word):
    list1 = list(word)
    for item in list1:
        if item == 'a' or 'e' or 'i' or 'o' or 'u' or 'A' or 'E' or 'I' or 'O' or 'U':
            try:  
                list1.remove(item)
            except ValueError:
                pass 
        print(list1)
    word = ''.join(list1)
    return word

1 Answer

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

your if is faulty. testing multiple conditions isn't done that way, it isn't interpreting it as if item == a or if item == e.....etc. you would have to explicitly put that, if item == a or item == e....etc, or use the in keyword to see if something is in a collection like a list. also debugging print statements may cause the challenge to fail. you are also modifying a list while looping over it, which results in skipping items. to fix make a copy and loop through that while modifying the original, or vice versa.