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

aditya verma
aditya verma
1,853 Points

Need help in solving this task, spent too much time.

How to split a word into a list of characters which i can then check for vowels? Or what am i not getting? Please help

disemvowel.py
def disemvowel(word):
    word=word.upper()
    list=word.split(' ')
    while 'A'or'E'or'I'or'O'or'U' in list:
        list.remove('A')
        list.remove('E')
        list.remove('I')
        list.remove('O')
        list.remove('U')
    new=' '.join(list)
    print(new)
disemvowel('aditya')

6 Answers

Efaz Khan
Efaz Khan
5,194 Points

Are you trying to print all the vowels in a given word? If so, then you should try the for loop to iterate over each letters and check if they are equal to any vowels.

def disemvowel(word):
  for letter in word:
    if letter.upper() in ('A', 'E', 'I', 'O', 'U'):
      print(letter)


disemvowel('aditya')
aditya verma
aditya verma
1,853 Points

Hi Efaz, I,m trying to remove any vowels present in a given word and print the remaining letters of the word ( without vowels)

Efaz Khan
Efaz Khan
5,194 Points

You can just use not in key word to print the non-vowels.

def disemvowel(word):
  for letter in word:
    if letter.upper() not in ('A', 'E', 'I', 'O', 'U'):
      print(letter)


disemvowel('aditya')

Let me know if this helps.

aditya verma
aditya verma
1,853 Points

Bummer: Hmm, got back letters I wasn't expecting! Called disemvowel('wAmadNWcV') and expected 'wmdNWcV'. Got back None

These are the responses Im getting. The same code is working well on my jupyter notebook but not here, somehow.

Sean M
Sean M
7,344 Points
vowels = ('a', 'e', 'i', 'o', 'u', 'A', 'I', 'E', 'O', 'U')

def remove_vowels(text):
    for char in text:
        if char in vowels:
            text = text.replace(char, '')
    return text

text = input("Enter word: ")
print(remove_vowels(text))
Sean M
Sean M
7,344 Points

If the challenge says use list specifically, I can try my best to use list.

rydavim
rydavim
18,813 Points

Okay, so there are several things going on here. Python isn't my strongest language, but I'll give it a shot. Don't be afraid to use print() statements to help debug and check your work at different steps.

def disemvowel(word):
    word=word.upper() # Using upper() here means you won't get back the same capitalization at the end.
    print(word) # ADITYA
    # Looks like list is a keyword, so you'll need to rename this.
    list=word.split(' ') # You're trying to split on a space, and there are none.
    print(str(list)) # ['ADITYA']
    while 'A'or'E'or'I'or'O'or'U' in list: # Your list only has one element, the upper word.
        # So none of the following will do what you're expecting.
        list.remove('A')
        list.remove('E')
        list.remove('I')
        list.remove('O')
        list.remove('U')
    new=' '.join(list) # You don't have any elements to join.
    print(new) # I think you need a return statement in here somewhere for this challenge.
disemvowel('aditya')

Here is one possible solution, but there are certainly other ways to solve this challenge. You can refer to Sean M 's answer for another way to do it.

# I believe you may assume you are only getting a single word as input.
def disemvowel(word):
    vowels = "aeiouAEIOU" # Make sure you check for both upper and lower case.
    my_list = list(word) # Here is that list keyword, converting your string to a list.
    for char in word: # Iterate through each character in the word.
        if char in vowels: # If the current character is in our list of vowels...
            my_list.remove(char) # ...remove it.
    word = ''.join(my_list) # Join your list back into a string, using an empty separator. 
    return word # Don't forget to return the word at the end.

If you still have questions, I will do my best to answer them. But like I said, Python is not one of my strongest languages. I know it can be frustrating sometimes, but keep it up!

Page Petty
Page Petty
2,928 Points

Yeah, I'm sorry, but this "Code Challenge" is STUPID. I figured out several ways to do this, but none conform to the starter code. And it was not really explained well enough how they wanted it done.

ALSO, I can't see when I would even want to ever use this IRL.

aditya verma
aditya verma
1,853 Points

can i get a moderator's view on this?