DEV Community

Discussion on: Problem in Python

Collapse
 
orenovadia profile image
orenovadia

1) Converting the number to a string
2) Using itertools.groupby to group each subsequent repeating digit
3) Concatenating each grouped digit with the size of its group
4) Concatenating the whole thing to one string

In [16]: ''.join(str(len(list(group))) + digit for digit, group in itertools.groupby(str(111115)))                                                                           
Out[16]: '5115'

(I interpreted the question so that the expected output for 151 is 111511 and not 2115).