8. Anti vowel. Need a little help here


#1

def anti_vowel(text):
    text = text.lower()
    table = []
    ban = ["i", "u", "o"]
    to_be_removed = []
    for lister in range(len(text)):
        table.append(text[lister])
      
    print table
      
    for letter in range(len(table)):
        if table[letter] in ban:
            to_be_removed.append(letter)
    print to_be_removed
      
    for index in range(len(to_be_removed)):
        table.pop(int(to_be_removed(index)))
          

        
anti_vowel("trytoremoveme")

I know the indeces of elements that i want to remove but i cant do it with pop(). What's wrong?


#2

What a complicated solution, but okay, lets go with it, there is a problem here:

for index in range(len(to_be_removed)):
        table.pop(int(to_be_removed(index)))

to_be_removed is already an array with the index of the items you want to remove it, so you can simple do:

for index in to_be_removed:
  table.pop(index)

however, this causes a problem. your items you want to remove are at index 4 and 8, right? (you print that with this line: print to_be_removed), but because you removed the letter at index 4, you now want to remove is at index 7, so you would have to loop over you remaining numbers in to_be_removed and decrease them by one. Also, e and a are also vowels.

It is easier to just append letters which are no vowels to a new array, hope this helps