Compress the String!

Sort by

recency

|

830 Discussions

|

  • + 0 comments
    from itertools import groupby
    
    x = input()
    
    def grouper(x):
        res = [(len(list(g)), int(k)) for k, g in groupby(x)]
        return print(*res)
    
  • + 0 comments

    s = input().strip() for key, group in groupby(s): key = int(key) result = [(len(list(group)), key)] print(' '.join(map(str, result)), end = " ")

  • + 0 comments
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    from itertools import groupby
    
    S = input()
    for i, combo in groupby(S):
        grp = len(list(combo))
        print((grp, int(i)), end=' ')
    
  • + 0 comments
    from itertools import groupby
    
    c = input()
    c_final = []
    
    for key, group in groupby(c):
        key = int(key)
        c_final.append((len(list(group)), key))
        
    print(*c_final)
    
  • + 0 comments

    from itertools import groupby A = input() for k, g in groupby(A): print(f"{len(list(g)), int(k)}", end=' ')