Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 16595

How to split a string entirely, but keep instances where letters repeat twice together?

$
0
0

I have a string like:

s = 'aaabcdedddd'

In this example, I would want to split the string into something like this.

s = ['aa', 'a', 'b', 'c', 'd', 'e', 'dd', 'dd']

Notice how the three-letter repeat of 'aaa' is not kept together, but rather considered a double repeat + a single letter ('aa'+'a'. The 'dddd' at the end is considered double repeat + double repeat ('dd'+'dd').

Is there any way to do this efficiently?


Viewing all articles
Browse latest Browse all 16595

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>