Compress the String!

  • + 0 comments
    from itertools import groupby
    s = input()
    list_s = [(len(list(g)),int(k)) for k,g in groupby(s)]
    print(" ".join(map(str,list_s)))
    

    OR

    from itertools import groupby
    s = input()
    [print((len(list(g)),int(k)), end=" ") for k,g in groupby(s)]