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

Completely lost. Challenge Task 1 of 1.

Can you help with a challenge? Everything looks fine but it's not working. Thank you in advance.

disemvowel.py
def disemvowel(word):
    vowels = ["a", "e", "i", "o", "u"]
    position = 0
    for letter in list(word):
        for vowel in vowels:
            if letter == vowel:
                list(word).remove(vowel)

    position = +1

    return word

1 Answer

Wade Williams
Wade Williams
24,476 Points

Few things, when using a for loop in python you don't need to keep a "position" variable, so let's remove that. By default a for loop will go through each character of a string, so no need to turn it into a list. We can do this in one loop, so let's get rid of the vowels for loop.

Your code has a lot going on, so let's describe the algorithm then code it up.

  1. Create a data structure to hold our vowels (Uppercase and Lowercase)
  2. Create a variable that will hold our result
  3. Loop through each character in word, if it's not a vowel then add it to our result
  4. return result
def disemvowel(word):
    vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
    result = ""

    for char in word:
        if char not in vowels:
            result += char

    return result

Thank you! Very interesting construction.