Ask coding questions

← Back to all posts
Double Letter Problem

So, I already made a post about a day ago asking for help making all double letters have an "x" in between them. Some nice guy helped me out a lot. The only problem is: I need to make a change to the code he gave me, and don't I know how.

The code he gave me turns every instance of this "hello" into this "helxlo" and "hheelloooo" into "hxhexelxloxoxoxo" which is what I wanted at the time.

Now I only want to change every set of double letters starting with an even number. For example "hello" becomes "helxlo", "abbcc" remains "abbcc" but "abbacc" becomes "abbacxc" because the first letter of the second set of double letters is even (fourth index).

I would really really appreciate the help of a smart person out there to give me a couple minutes of their day and take a look at my code. The code which I am working on is at the bottom, not in the comments.


Hi again @Alex0204, I just put this on your first post, but then I saw this thread.
Here you go- Added one more IF statement if (i % 2) != 0:


The solution you came up with seems to work; it's just skipping every other letter. It seems possible that you might run into issues with certain words using this method, depending on where the doubles land. Kudos on finding a solution - Best of luck!


@Alex0204 Hi,
I just checked out your Repl.
It's working as you said!

abbacc is turning into abbacxc
hello is turning into helxlo

Hope this helps


@PattanAhmed Yeah. I actually realized the solution on my own shortly after I made this post. I just change line 211 from:

for i in reversed(range(1,len(char))):


for i in reversed(range(1,len(char), 2)):

Thanks anyway bro!


@Alex0204 Welcome!
I am so happy that it is solved :)
If you have any more questions or problems, don't forget to post on Ask board


Happy to help you anyways!
Please mark my answer if that helps