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

Pitrov Secondary
Pitrov Secondary
5,121 Points

Can you help me with this coding challenge?

I cant figure out what is wrong here. Is there a place I can see the answer, or do I have to ask the community?

disemvowel.py
def disemvowel(word):
    for letter in word:
        if letter.upper in 'A' or 'E' or 'I' or 'O' or 'U':
           del letter
    return word

print(disemvowel('iamthebest'))

1 Answer

Ernestas Petruoka
Ernestas Petruoka
1,856 Points

Hi mate I am still learning to so my code probably ain't perfect, but working. So first thing I did in this challange was converting string to list in new variable by doing word = list(word) because strings are imutable and lists are mutable and we do need change that string. then created list of all vowels by doing L = ['A', 'E', 'I', 'O', 'U']. then I started loop for letter in L: and checked if letter is vowel or not with if letter.upper() in L: (BTW you missed () in your code) and if it is true then I do word.remove(letter) and in the end I simply return list converted into string by return ''.join(word). My whole code looks like this:

def disemvowel(word):
    word = list(word)
    L = ['A', 'E', 'I', 'O', 'U']
    for letter in word.copy():
        if letter.upper() in L:
           word.remove(letter)
    return ''.join(word)

That's it. :) BTW Sorry if I made some grammar mistakes, my english is far away from perfect :)

Pitrov Secondary
Pitrov Secondary
5,121 Points

Thanks for the answer, it works! I did not notice any grammar mistakes, do you know of Grammarly? It helps me out when I write something in English. I spent so much time on that one, because I forgot about list(), I did not know how to make it into a list