You are viewing a single comment's thread. Return to all comments →
Instead of importing itertools , we can write code below
s= input() out=[] r=1 for i in range(len(s)): if i< len(s)-1 and s[i]==s[i+1]: r+=1 else: out.append((r,int(s[i]))) r=1 print(*[j for j in out ])
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 →
Instead of importing itertools , we can write code below
s= input() out=[] r=1 for i in range(len(s)): if i< len(s)-1 and s[i]==s[i+1]: r+=1 else: out.append((r,int(s[i]))) r=1 print(*[j for j in out ])