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

Pratham Patel
Pratham Patel
4,976 Points

Can I get some help with this code challenge

I don't see what I did wrong

disemvowel.py
def disemvowel(word):
    vowels = ["a", "e", 'i', 'o', 'u']
    a = input("Give me an vowel: ")
    if a.upper() in vowels.upper():
        a.remove(a)
    else:
        print("try again")
        continue
    return word

2 Answers

Josue Ipina
Josue Ipina
19,212 Points

First, the challenge requires you to just take the given word argument, remove the vowels, and then return it. So you don't need to get any new input, just take word, iterate through it checking for vowels and remove them.

You can do it like this:

def disemvowel(word):
    #split word into a list containing each character
    mylist = list(word)

    #iterate through each letter in the (non-split) word
    for letter in word:
        if letter in 'aeiouAEIOU':         #if the selected letter is contained in 'aeiouAEIOU'
            mylist.remove(letter)          #remove that letter from the list
    return ''.join(mylist) #return the joined list of characters

a.remove(a) I think you meant vowels