Home > Net >  Can someone tell me the code fro the following question
Can someone tell me the code fro the following question

Time:11-12

A="abbccdda" this is input Output should be 1a2b2c2d1a .can someone please tell me the code in python for this question

I tried the code and its printing all characters but last one character is missing

CodePudding user response:

what have you tried so far ? You need to produce some examples in order to expect outputs from community...

Update your question. For this time I'm provinf answer because I recently solved this similar type of solution.

a ="abbccdda"

mask = ''
count = []

for i in a:
    if i == mask:
        count[-1] = [i,count[-1][1]  1]
        
    else:
        count.append([i,1])
        
        mask = i
count = [i[::-1] for i in count]

print("".join(["".join([str(item) for item in sublist]) for sublist in count]))

output #

1a2b2c2d1a

CodePudding user response:

txt = input("enter text : ")

data = ""

a = 0

letter = ""

e = 0

for i in txt :

    if a == 0 :

        letter = i

        a  = 1

    elif i == letter :

        a  = 1

    elif i != letter :

        data  = str(a) letter

        a = 1

        letter = i

    e  = 1

data  = str(a) letter

print(data)

If you want try this. This is more understandable. Good lucky!

  • Related