We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Itertools
- Compress the String!
- Discussions
Compress the String!
Compress the String!
Sort by
recency
|
789 Discussions
|
Please Login in order to post a comment
s=input() count=1 for i in range(1,len(s)): if s[i]==s[i-1]: count+=1 else: print((count,int(s[i-1])),end=" ") count=1 print((count,int(s[-1])))
from from itertools import groupby as gr
p=[]
[p.append(int(i)) for i in ' '.join(input()).split()]
[[print(o,end = ' ') for o in i.items()] for i in [{len(list(o[1])):o[0]}for o in gr(p)]]