[Solved] How to split string into substrings of identical letters?


The following list comprehension using itertools.groupby and str.join will work:

from itertools import groupby

s = "aaaabbcccdd"
[''.join(g) for _, g in groupby(s)]
# ["aaaa", "bb", "ccc", "dd"]

1

solved How to split string into substrings of identical letters?