Compress the String!

  • + 0 comments

    from itertools import groupby

    Reading input

    s = input()

    Using groupby to group consecutive identical characters

    result = [(len(list(group)), int(key)) for key, group in groupby(s)]

    Printing the result with the required format

    print(*result)