0
Almost done
def get_part(input): if len(input) <= 1: return input num=int(input.split(input[-1],2)[0]) return num*input[-1] def get_line(input): parts=[] for i in input.split(" "): parts.append(get_part(i)) return "".join(parts) n=input() inputs=[] inputs.append(n) for input in inputs: print(get_line(input)) if i input : 4bab 18c 12g outout : bbbbccccccccccccccccccgggggggggggg how to make it output is babbabbabbabccccccccccccccccccgggggggggggg
1 Respuesta
+ 1
using regular expressions to get the number part from the string part.
if there is no number part or there is no text part, print the entry data.
^([1-9][0-9]*)([^1-9].*)$ means:
it starts with a digit between 1 and 9, following 0 or more digit between 0 and 9. that's the number part. the text part starts after a non digit character appears which may be followed anything.
import re
def get_part(input):
m = re.search('''^([1-9][0-9]*)([^1-9].*)#x27;'',input)
if m is not None:
return (int(m.group(1)),m.group(2))
return (1,input)
def get_line(input):
parts=[]
for i in input.split(" "):
(count,str)=get_part(i)
parts.append(str*count)
return " ".join(parts)
inputs=[]
inputs.append("4a 3c 9o 0")
inputs.append("11b 3keke 9")
inputs.append("2b0ss 3keke x")
inputs.append("l77t is 2n33t")
for input in inputs:
print(get_line(input))
-------output-------
aaaa ccc ooooooooo 0
bbbbbbbbbbb kekekekekeke 9
b0ssb0ss kekekekekeke x
l77t is n33tn33t