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

why my code is not running? please help!!

i don't know why this is not running

disemvowel.py
def disemvowel(word):
    for i in word:
        if i.lower() in ['a','e','i','o','u']:
            word.remove(i)
        elif i.upper() in ['A','E','I','O','U']:
            word.remove(i)
    return word
Ari Misha
Ari Misha
19,323 Points

Hiya Ekjot! This can be done in few lines and without using lowercases and uppercases. Here is the code(insteading of copying it try to get the logic behind it):

def disemvowel(word):
    v_list = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']
    new_list = []

    for i in word:
         if not i in v_list:
            new_list.append(i)
    return "".join(new_list)

1 Answer

Gustavo Winter
PLUS
Gustavo Winter
Courses Plus Student 27,382 Points
def disemvowel(word):
    final_word = ''   
    vogals = ['a', 'e', 'i', 'o', 'u']
    for letter in word:
        if letter.lower() not in vogals:
            final_word += letter
    return final_word

1 -This work for me.

2 - First you set a empty variable "final_word".

3 - Then you set the vogals.

4 - Check if the letter has the declared "vogals".

5 - add the remaining letter for our empty variable.

6 - and to finish the challange return the variable "final_word".

I hope i have helped.

thank you Gustavo winter