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 Removing Items From A List

gabrieL faurE
gabrieL faurE
1,697 Points

disemvowel challenge

Hi i allready did the disemvowel challenge, but with another method, i don know why with this code i cant remove the last "e"

    word ="bUVOnEe"
    def disemvowel(word):
        l=len(word)
        print(l)
        word=list(word)
        a=0
        while a <=l:
            try:
               if word[a] in ["a","e","i","o","u","A","E","I","O","U"]:
                    del word[a]
                    a+=1
                else:
                    a+=1
            except IndexError:
                a+=1

        print(word)
    disemvowel(word)

1 Answer

gabrieL faurE
gabrieL faurE
1,697 Points

ok got it

def disemvowel3(word):
    l = len(word)
    word = list(word)
    word2 = word
    print(word)
    vocals = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
    a = 0
    b = 0
    while a <= l:
        print("a = {}".format(a))
        try:
            if word[a] in vocals:
                del word2[a]
                print("delete {}".format(a))
                print(word2)


            else:
                print("els{}".format(a))
                a += 1
        except:
            print("ex {}".format(a))
            a += 1
Justin Henley
Justin Henley
2,968 Points

Can you please explain to me this code. I looked through it trying to understand, but am struggling. I copied and tried running it and it returned a bunch of seemingly nonsensical values