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

competent- fellow
competent- fellow
5,846 Points

How to remove last vowel?

Here is my code for the "disemvowel" exercise. Every time it fails to remove the last vowel. e.g. passing "tomatoes" returns "tmtes". But I don't know what is wrong. Thanks in advance!

disemvowel.py
def disemvowel(word):
    word_list = list(word)
    copy_list = word_list
    vowels = ["a", "A", "e", "E", "i", "I", "O", "o", "U", "u"]
    for letter in copy_list:
        if letter in vowels:
            word_list.remove(letter)
    word = ''.join(word_list)
    return word

1 Answer

Steven Parker
Steven Parker
229,744 Points

You had the right idea to make a copy of the list for controlling a loop. But a simple assignment doesn't make a copy, it just causes both variables to reference the same list.

To make a copy, use an empty slice ("[:]") or the ".copy()" method.

competent- fellow
competent- fellow
5,846 Points

The .copy() method worked perfectly. Thank you very much!