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
|
855 Discussions
|
Please Login in order to post a comment
Here is HackerRank Compress the String! in python solution - https://programmingoneonone.com/hackerrank-compress-the-string-solution-in-python.html
import itertools
if name == 'main': S = input()
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 ])