input="AABBBBCDDDABC" output=2A4B1C3D1A1B1C | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 1

input="AABBBBCDDDABC" output=2A4B1C3D1A1B1C

input="AABBBBCDDDABC" need output=2A4B1C3D1A1B1C

2nd Feb 2022, 9:26 AM
Manoj Bhaagam
7 Réponses
+ 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
2nd Feb 2022, 9:49 AM
Rishi
Rishi - avatar
+ 2
Show your attempt first, how far did you try? Do you have a code? If yes where are you stuck?
2nd Feb 2022, 9:34 AM
Rishi
Rishi - avatar
+ 2
Tell me how you can solve this?
2nd Feb 2022, 9:38 AM
Manoj Bhaagam
+ 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)
2nd Feb 2022, 10:07 AM
Alexey Kopyshev
Alexey Kopyshev - avatar
+ 2
Alexey Kopyshev thank you
2nd Feb 2022, 10:17 AM
Manoj Bhaagam
+ 1
Asynchronous
2nd Feb 2022, 9:28 AM
Manoj Bhaagam
+ 1
input="AABBBBCDDDABC" output = {} for i in input: output[i]=input.count(i) print(output)
2nd Feb 2022, 9:37 AM
Manoj Bhaagam