Code pentry Big Data

This is the code i have for the above problem
practice : Big Data
I have submitted following code

from itertools import groupby
def compress(s):
    sg = groupby(s)
    rets= ""
    for i, g in sg:
        lens = len(list(g))
        if lens > 1:
            rets += str(lens) + i
            rets += i
    return rets

def get_score(s):
    score = 0
    for i in s:
        if i.isdigit():
            score += 32
            score += 8
    return score

for _ in range(int(input()))              :
    ins = input()
    com = compress(ins)
    print(len(ins) * 8  - get_score(com))

Can someone please tell me why it is failng.
Thanks in advance.

Your compress function is not correct. Try s=abcc

shouldโ€™nt that be ab2c as output by my compress function.

It should be ab2c. But it does not matter as you are only changing position. For s=012, output should be 0
According to question, you have to consider number as character in original string. So, length of original string is 8size. After compression only the integer which represent its count will be taken as number.
For 00012
after compression 0312 , size2=8+32+8+8=56
So answer will be -16

1 Like

So basically what you are saying is given input may contains numbers . And they should be
treated as chars and not digits.
Points noted.
here is AC for this problem

from itertools import groupby

for _ in range(int(input())):
    ins = input()
    insg = groupby(ins)
    score = 0
    for i, g in insg:
        if len(list(g)) > 1:
            score += 40
            score += 8
    lens = len(ins) * 8
    print(lens - score)

Yeah :+1: