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

TypeError: can only join an iterable

But variable letters is a list, so therefore the join function should have worked. What seem to be the problem with my code?

disemvowel.py
def disemvowel(word):
    vowels = ["a","e","i","o","u"]
    upper_vowels = ["A","E","I","O","U"]
    letters = list(word)

    for vowel in vowels:
        try:
            if vowel in word:
                letters = letters.remove(vowel)
        except:
            pass


    for vowel in upper_vowels:
        try:
            if vowel in word:
                letters = letters.remove(vowel)
        except:
            pass

    word = ", "
    word = word.join(letters)
    return word

1 Answer

Dave StSomeWhere
Dave StSomeWhere
19,870 Points

:tropical_drink: Two issues immediately pop out from your code.

  1. The remove() method does not return any value. Your statement:
letters = letters.remove(vowel)  # this will set letters to none - no longer an iterable
  1. The remove() statement only removes the first occurrence found.
    for vowel in vowels: #  this will only remove the first vowel occurrence
        try:
            if vowel in word:
                letters = letters.remove(vowel)
        except:
            pass

I would suggest investigating looping letters and do a remove when you get to a vowel. I would also suggest investigating python string methods like upper() and lower() if you'd like to simplify a bit. :palm_tree:

Thanks! I forgot that the remove function doesn't return a value.