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

disemvowel

So i have been working on this for a while, and i got this far, but I do not know what to put after the for in loop. Any help?

disemvowel.py
def disemvowel(word):
    return word


wordlist = list(word)
vowelslist = ['a','A','e','E','i','I','o','O','u','U']

for vowel in vowelslist:

3 Answers

Steven Parker
Steven Parker
231,269 Points

It sounds like you want some general strategy hints. I assume you want to remove each "vowel" from the word. Since you have converted the word into a list, you could use another loop to perform "remove"s on the list. You could also work directly on the word using a string's "replace" method.

Either way, check your indentation and remember to move the "return" to the end of the function.

i'm sorry i still didnt' get it. If you do not mind to help me a wee bit more?

Steven Parker
Steven Parker
231,269 Points

Sure, but where are you now? Did you fix the indentation yet? Have you decided if you want to work with a list or a string?

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

for vowel in vowelslist:
    list.remove(vowelslist)
    return word
Steven Parker
Steven Parker
231,269 Points

Ok, here's some more hints:

  • the loop still needs to be indented to be part of the function
  • the "remove" is working on "list", but nothing named "list" was defined (did you mean "wordlist"?)
  • the argument to "remove" should be a single vowel instead of the whole list of them
  • the "wordlist" is not being converted back into a string
  • the original "word" is being returned unchanged.

i got to here, but i still don't get it. I am a little confused on the for in loop. Would you mind explaining it a bit more? Sorry to bother you.

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


    for vowel in vowelslist:
        wordlist.remove(vowelslist)
        return word
Steven Parker
Steven Parker
231,269 Points

The "return" should not be inside the loop. As it is now, the function will end on the first pass in the loop.

The "return" is giving back the original "word". But you want to return a modified version (with no vowels).

The loop is working on a list, but the function needs to return a string. So you need to re-join the list after the loop.

thanks. I tried this and it worked.

def disemvowel(word):
  vowelslist = ['a','A','e','E','i','I','o','O','u','U']
  for i in vowelslist:
    if i in word:
      word = word.replace(i, '')
  return word
Steven Parker
Steven Parker
231,269 Points

Your persistence paid off, good job! :+1: