OK So the problem I had was a simple fix.
Originally, the problem I had was that I had a string index out of range error.
The solution: I added this to my code after line 16:
index_counter = len(text_without_vowels)-1
Then I called that new variable on the next line:
return vowel_delete(index_counter, text_without_vowels)
This solved the string indexing issue. Essentially, every time the function detects a vowel, after the vowel is removed in the text_without_vowels variable, it resets the length of the text string, -1 to account for zero index.
This solved the string indexing issue.
I have found that the text.replace() function replaces ALL of the characters in the string, not just a character at that one index. I will continue to fine-tune this algorithm now.
So I'm working on this problem recursively, but running into a problem. I'm wondering if it might have to do with memory, but I think it may be something else instead.
Running with what I have, "Hey You!" returns correctly as "Hy Y!"
However, when it passes "How does it feel? To be on your own?" it throws an IndexError: string index out of range
If you run what I have written so far, it throws the error on the first pass over a vowel in that long string (specifically, the 'o'). I don't think it should be doing that, but I can't figure out why.
On a side note, yes, I know recursive functions in python is a memory hog, but it's an extra challenge for me since I ma weak with recursive functions.
def anti_vowel(text): counter = len(text)-1 if counter <= 1: return text else: return vowel_delete(counter, text) def vowel_delete(index_counter, text): vowels = "aeiouAEIOU" if index_counter < 0: return text elif text[index_counter] in vowels: text_without_vowels = text.replace(text[index_counter], "") print text[index_counter], text return vowel_delete(index_counter-1, text_without_vowels) else: print index_counter return vowel_delete(index_counter-1, text) print anti_vowel("Hey You!") print anti_vowel("How does it feel? To be on your own?")