Question: I am trying to write a function that takes a string as input and returns a string with all vowels repeated 4 times. 

*eg: `apple` becomes `aaaappleeee`*

It works for every vowel, except for *e*, in which it repeats *e* an egregious amount of times.

Python 3. I have tried playing with the replace function, changing the replacement value to `i+i+i+i`, `i*4`, `i(4)`, `(i+i)*2`, but nothing seems to help. 

```
def exclamation(string):
    for i in string:
        if i in 'aeiou':
            string = string.replace(i, i*4)
    return string + '!'

```

`exclamation('excellent')` should return `eeeexceeeelleeeent!`

however, it returns:
 `eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeexceeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeelleeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeent!`

As stated, the function works fine for all other vowels, except *e*.

Thank you!

Answer: 
For every vowel you’re iterating through, the loop checks the condition, replaces the content in the same string and then iterates by 1 which now is the same string but instead of the next new letter, it now has to deal with 3 more of the same vowel. For example:

Let’s talk about the string ‘excellent’. For the first vowel ‘e’, it is replaced with ‘eeee’ resulting in the string being ‘eeeexcellent’, now when the second loop begins it starts at index(1) which is still an ‘e’ and this keeps going on. **Never modify the iterable you’re iterating over.**
It is happening because your loop will consider the replaced 'e's as the element of the string as well.

Here is what I am saying:

* String is excellent
* Iterate through the string and check if the letter is vowel
	+ If the letter is vowel, write that vowel 4 times.

By following the above steps, we will find this result as the first iteration. 

First iteration will work on the first letter which is 'e' and will replace it with 'eeee'. So at the end of the first iteration, our final string will be: **'eeeexcellent'** 

Now for the second iteration, *it will consider the final string* we got after the first iteration. And for second iteration, the word to be consider will be 'e' only. So as you can see, you need to maintain the string as it is after each iteration, and save the replaced result to a new string. (it will always be a new string after all as string is not mutable)

```
def exclamation(string):
    tmp = ''               #taking temporary variable to store the current data
    for i in string:
        if i in 'aeiou':
            tmp += i*4     # i*4 only if i is vowel
        else:
            tmp += i       # keeping i as it is if it's not vowel
    return tmp + '!'

```

You can also try list list comprehension which is easy to read and understand as well:

```
def exclamation(string):
        newstr = [ i*4 if i in 'aeiou' else i for i in string]
        return ''.join(newstr)+'!'

```