Compress the String!

Sort by

recency

|

872 Discussions

|

  • + 0 comments

    from itertools import groupby

    A = input()

    B =groupby(A)

    for i, k in B: print((len(list(k)), int(i)), end=" ")

  • + 0 comments
    from itertools import groupby
    
    if __name__ == "__main__":
        s = input()
        print(" ".join(f"({len(list(group))}, {key})" for key, group in groupby(s)))
    
  • + 0 comments
    import itertools
    string = input()
    groups = itertools.groupby(string)
    results = []
    for key, group in groups:
        count = 0
        for item in group:
            count += 1
        results.append((count, int(key)))
    
    print(*results)
    
  • + 0 comments
    from itertools import groupby
    s = input()
    for key, group in groupby(s):
        print((len(list(group)), int(key)), end=" ")
    
  • + 0 comments

    from itertools import groupby s1=(input()) list1=[] for k, g in groupby(s1):
    list1.append((len(tuple(g)),int(k))) print(*list1)