Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (2016, retired 2019) Lists Disemvowel

Adam Ryde
Adam Ryde
5,222 Points

Disemvowel

here is my code.... its late, i have been at work since 5am and i just cannot get my brain to function around this. my way of thinking was, if i put the upper and lower case values of vowels into lists of their own, i could then use those lists to find the vowels and delete them?

i am guessing i was wrong.

def disemvowel(word): vowels_lower = ["a", "e", "i", "o", "u"] vowels_upper = ["A", "E", "I", "O", "U"]

if vowels_lower in word:
    del vowels_lower
elif vowels_upper in word:
    del vowels_upper

return word
disemvowel.py
def disemvowel(word):
    vowels_lower = ["a", "e", "i", "o", "u"]
    vowels_upper = ["A", "E", "I", "O", "U"]

    if vowels_lower in word:
        del vowels_lower
    elif vowels_upper in word:
        del vowels_upper

    return word

1 Answer

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

this throws an error because you are asking if a list is in a string. there's a method in python (lower) that you can call on a string like myString.lower() that will return a lower-case version of myString. you can store that in a variable, cast it to a list and loop through it, removing the vowels from a copy of the list (you must avoid looping through a list that you are simultaneously modifying), or just append the consonants to a new string. either way you should end up with the correctly disemvoweled word.