You are viewing a single comment's thread. Return to all comments →
from itertools import groupby
Reading input
s = input()
Using groupby to group consecutive identical characters
result = [(len(list(group)), int(key)) for key, group in groupby(s)]
Printing the result with the required format
print(*result)
Seems like cookies are disabled on this browser, please enable them to open this website
Compress the String!
You are viewing a single comment's thread. Return to all comments →
from itertools import groupby
Reading input
s = input()
Using groupby to group consecutive identical characters
result = [(len(list(group)), int(key)) for key, group in groupby(s)]
Printing the result with the required format
print(*result)