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

Salman Badshah
Salman Badshah
1,473 Points

I dont understand what am I doing wrong with the challenge?

So this is my code. I don't know whats wrong but this should work? Can someone please help?

disemvowel.py
def disemvowel(word):
    if word:
        try:
            word.remove('a') or word.remove('A') or word.remove('e') or word.remove('E') or word.remove('i') or word.remove('I') or word.remove('o') or word.remove('O') or word.remove('u') or word.remove('U')
        except ValueError:
            pass
    return word

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,426 Points

The code fails for the following reasons:

  • the string passed into word does not have a remove attributes. Instead, create a list out of word first. Remember to convert back to a string using the join() method before returning word
  • By using series of or conditions, the removals will stop on the first vowel not found. Instead, you will need to use a loop check each character in word character list.
  • Without a loop, repeated vowels would not be removed, only the first occurrence.

Post back if you need more help. Good luck!!

Salman Badshah
Salman Badshah
1,473 Points

Ok so, in the end, do I have to convert my list back to a string before returning it? For your second point you mean to say I need to use a for loop? I am sorry I don't quite understand what or-ed expressions are?

Chris Freeman
Chris Freeman
Treehouse Moderator 68,426 Points

Yes, you'll need to convert to a list at the start and back to a string at the end. Yes, you will need a loop. By or-ed expressions, I meant a series of or conditions.

I've corrected my answer to reflect this.