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

Mujahid Chowdhury
Mujahid Chowdhury
5,108 Points

Help with disemvomel challenge

I am meant to remove all vowels from 'word' then return the final word. Here is my code:

def disemvowel(word): for w in word: if w == 'a' or 'A': w.lowercase() word.remove(w) elif w == 'e' or 'E': w.lowercase() word.remove(w) elif w == 'i' or 'I': w.lowercase() word.remove(w) elif w == 'o' or 'O': w.lowercase() word.remove(w) elif w == 'u' or 'U': w.lowercase() word.remove(w) else: continue return word

Any ideas why it doesn't work?

disemvowel.py
def disemvowel(word):
    for w in word:
        if w == 'a' or 'A':
            w.lowercase()
            word.remove(w)
        elif w == 'e' or 'E':
            w.lowercase()
            word.remove(w)
        elif w == 'i' or 'I':
            w.lowercase()
            word.remove(w)
        elif w == 'o' or 'O':
            w.lowercase()
            word.remove(w)
        elif w == 'u' or 'U':
            w.lowercase()
            word.remove(w)
        else:
            continue
    return word

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! Your code contains a series of errors. First, there is no method lowercase(). You are looking for lower(). Secondly, you may not use remove() on a string, which is what is being sent in. You may, however, use remove on a list. Third, if you choose the route to use the remove method on a list, you need to account for what happens to the indexing of your iterable. It's generally a bad idea to mutate the thing you're iterating over. If you use remove() on the list you're iterating over, some checks will be skipped entirely. Try iterating over a copy instead.

Hope this helps! :sparkles: