You are viewing a single comment's thread. Return to all comments →
if name=='main':
s=input()
count=0
prev=s[0]
flag = True #to handle edge cases
l=[]
for i in range(len(s)):
tu=[] value=s[i] if prev==value: count = count+1 else: flag = False tu.append(count) tu.append(int(prev)) l.append(tu) prev = value count = 1
if flag == True:
tu=[] tu.append(count) tu.append(int(prev)) l.append(tu)
else:
for i in l: print(tuple(i), end=" ")
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 →
if name=='main':
count=0
prev=s[0]
flag = True #to handle edge cases
l=[]
for i in range(len(s)):
if flag == True:
else:
for i in l: print(tuple(i), end=" ")