Compress the String!

Sort by

recency

|

825 Discussions

|

  • + 0 comments
    from itertools import groupby
    groups = []
    uniquekeys = []
    data = input().strip()
    for k, g in groupby(data): 
        groups.append(len(list(g)))      
        uniquekeys.append(int(k))
    print(*list(zip(groups,uniquekeys)))
    
  • + 0 comments

    from itertools import groupby

    s = input()

    for k, g in groupby(s): print((list(g).count(k),int(k)), end = " ")

  • + 0 comments

    from itertools import groupby

    s = input().strip() result = []

    for key,group in groupby(s): count = len(list(group)) result.append(f"({count},{key})")

    print(" ".join(result))

  • + 0 comments
    from itertools import groupby
    print(*[(len(list(g)), int(k)) for k, g in groupby(input())])
    
  • + 0 comments
    from itertools import groupby
    if __name__ == "__main__":
        data = input()
        result=[]
        for key, group in groupby(data):
            s=[]
            s.append(len(list(group)))
            s.append(int(key))
            print(tuple(s),end=" ")