You are viewing a single comment's thread. Return to all comments →
s = input()
compressed = [] count = 1
for i in range(1, len(s)): if s[i] == s[i - 1]: count += 1 else: compressed.append((count, int(s[i - 1]))) count = 1
compressed.append((count, int(s[-1])))
print(' '.join(str(tup) for tup in compressed))
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 →
s = input()
compressed = [] count = 1
for i in range(1, len(s)): if s[i] == s[i - 1]: count += 1 else: compressed.append((count, int(s[i - 1]))) count = 1
compressed.append((count, int(s[-1])))
print(' '.join(str(tup) for tup in compressed))