Compress the String!

Sort by

recency

|

855 Discussions

|

  • + 0 comments
    import itertools
    
    print(" ".join(f"({len(list(g))}, {k})" for k, g in itertools.groupby(input())))
    
  • + 0 comments

    Here is HackerRank Compress the String! in python solution - https://programmingoneonone.com/hackerrank-compress-the-string-solution-in-python.html

  • + 0 comments

    import itertools

    if name == 'main': S = input()

    result = [(len(list(group)), int(key)) for key, group in itertools.groupby(S)]    
    
    
    for item in result:
        print(item , end=' ')
    
  • + 0 comments
    from itertools import groupby
    a=input()
    for k,v in groupby(a):
        print((len(list(v)),int(k)),end=" ")
        
    
  • + 0 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 ])