# Help! 15 - 8 ANTI_VOWEL

#1

Error:
Traceback (most recent call last):
File "python", line 18, in
File "python", line 6, in anti_vowel
IndexError: list index out of range

I know this isn't the most efficient way, but I really want to know why this doesn't work! Any help is greatly appreciated

``````Replace this line with your code.
def anti_vowel(text):
temp = []
for i in range(len(text)):
temp.append(text[i])
for j in range(len(temp)):
if temp[j] == "a" or temp[j] == "A":
del temp[j]
elif temp[j] == "e" or temp[j] == "E":
del temp[j]
elif temp[j] == "i" or temp[j] == "I":
del temp[j]
elif temp[j] == "o" or temp[j] == "O":
del temp[j]
elif temp[j] == "u" or temp[j] == "U":
del temp[j]
return "".join(temp)

print anti_vowel("anti vowel")
print anti_vowel("don't take away my vowels please!! :(")``````

#2

I am not sure but the Index error occures because i and j cant be used as an Index for your list (i and j just goes trough every value in the list but its not the index because the first value in your list has the index 0). I would define a variable for the index for example index = len(temp). --> temp[index] == "e" . It could work

#3

Hi

You are checking the condition and if success you are deleting that element.
That results in the reduce of the length of that list by one each time.
Finally resulting in out of index.

For the same exercise it can be executed in a better way as below.

1) Put all the vowels in the list.
2) Initialise an empty list.
3) Iterate on text and check each iterator value not in vowels list.
It true, append to the new list.
4) Lastly use join function on the new list.

#4

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