Anti_vowel help


#1



Hello everyone! My codes display "Hy Lk Words!" instead of "Hy Lk Wrds!" I don't know why it worked for the first two "o"s, but not the last one. Can anyone help me? thx.


def anti_vowel(text):
    checklist = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']
    translist = []
    for char in text:
        translist.append(char)
    for n in translist:
        for x in checklist:
            if n == x:
               translist.remove(n)
    return ''.join(translist)
print anti_vowel("Hey Look Words!")


#2

The code sees the first and third o but removes the first and second.


#3

thank you very much. I understand now.
for--in loop accesses list by index and list.remove() changes the index. so an "o" is skiped.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.