I'm trying to make a function that, for every occurrence of a vowel in a string, reverses said-string (and includes the vowel when it does this). The function is somewhat complex for my understanding so I'd like some help and a maybe a breakdown of it. However, I would only like to use the operators and statements that I'm currently learning (for/while and if). If possible, I would also like to avoid using list comprehension.
Here's what the inputs and outputs should look like:
an example input would be reverse_per_vowel('aerith')
which returns 'iraeth'
If we break the process of this function into steps, it should look like:
(a)erith → (a)erith (the first letter is a vowel, so it is reversed. However, because it is the first letter in the string, there are no visible changes.)
(ae)rith → (ea)rith (the second letter is also a vowel, so every letter in the string leading up to and including the vowel is reversed.)
(eari)th → (irae)th (the fourth letter is a vowel, so everything leading up to and including it is also reversed. Note how it accounts for the letters in the string that were reversed previously.)
as you can see, the amount of times the string is reversed is cumulative and I'm not quite sure how to code for this. However, I've attempted to write a component of the function.
What I'm trying
vowellist = 'aeiouAEIOU'
sampleword = 'aerith'
indexlist = []
for i in range(len(sampleword)):
if sampleword[i] in vowel_list:
indexlist.append(i)
indexlist
output: [0, 1, 3]
this excerpt does not reverse any parts of the string, however it returns indexes where the string should be reversed. What I planned on doing was plugging these indexes back into the sample word somehow and using [::-1] to reverse a portion of the string. However, I don't know how I would do this nor if it would be a good idea. Any help would be appreciated.