Compress the String!

  • + 0 comments
    from itertools import groupby
    
    S = input()
    result = []
    
    for num, group in groupby(S):
        length = len(list(group))
        result.append((length, int(num)))
    
    print(" ".join(str(x) for x in result))