Compress the String!

  • + 0 comments

    Sometimes you need to try to solve the problem with your onw logic. and here is mine, , whats do you think champs ?

    s = '1222311'
    count = 1
    for i in range(1, len(s)):
        # if i+1 < len(s):
        # print(i, i-1)
        if s[i] == s[i-1]:
            count += 1
        else: 
            print(f"({count}, {s[i-1]})", end=' ')
            count = 1
    print(f"({count}, {s[-1]})")