Splitting a string with repeated characters into a list

Use re.finditer():

>>> s="111234"
>>> [m.group(0) for m in re.finditer(r"(\d)\1*", s)]
['111', '2', '3', '4']

Leave a Comment