+ 1
input="AABBBBCDDDABC" output=2A4B1C3D1A1B1C
input="AABBBBCDDDABC" need output=2A4B1C3D1A1B1C
7 Answers
+ 3
Manoz Bagam loop through the string character by character. For each character, count how many characters following it, is same, then print the character plus it's count. Then skip all those same characters and start from the next character. This is one way of solving this question
+ 2
Show your attempt first, how far did you try? Do you have a code? If yes where are you stuck?
+ 2
Tell me how you can solve this?
+ 2
from functools import reduce
inp = "AABBBCDDDABC"
out = reduce(lambda y,x: y+"1"+x if y[-1] != x else y[:-2]+str(int(y[-2])+1)+x, inp[1:], "1"+inp[0])
print(out)
+ 2
Alexey Kopyshev thank you
+ 1
Asynchronous
+ 1
input="AABBBBCDDDABC"
output = {}
for i in input:
output[i]=input.count(i)
print(output)