I have already tried this (as sombody told me on another question):
import re
def decode(txt):
list = []
for cnt, char in re.findall(r"([\d*])([^d])", txt):
list.extend((char * (int(cnt) if cnt else 1)))
list = "".join(list)
return list
Example:
print(decode("2CACA2CACA3CACACA3CAC"))
This is what I get
CCCCCCCCCC
And this is what I need
CCACACCACACCCACACACCCAC
>Solution :
What you are missing is characters without a digit in front. This will include those:
import re
def decode(txt):
_list = []
for cnt, char, single_char in re.findall(r"(\d)([^\d])|([^\d])", txt):
if single_char:
_list.extend(single_char)
else:
_list.extend((char * (int(cnt) if cnt else 1)))
_list = "".join(_list)
return _list
print(decode("2CACA2CACA3CACACA3CAC"))