+ 1

Please help

how to make a code with testcase like input : 4a 3c 9o 0 output : aaaacccooooooooo0 input : 11b 3k 9 output : bbbbbbbbbbbkkk9

5th Jan 2017, 9:28 AM
Angel
Angel - avatar
5 Answers
+ 2
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) inputs=[] inputs.append("4a 3c 9o 0") inputs.append("11b 3k 9") for input in inputs: print(get_line(input))
5th Jan 2017, 10:06 AM
DFX
DFX - avatar
+ 1
your answer is rightt i just replace it with new variable with input. thankyou so muchhh gbu
5th Jan 2017, 10:28 AM
Angel
Angel - avatar
+ 1
@DFX but if i input 8dad 7a. the output just dddddddd aaaaaaa. how to have the output is daddaddaddaddaddaddaddad aaaaaaa
5th Jan 2017, 10:36 AM
Angel
Angel - avatar
+ 1
@Alex: Ah, I did not except that input because it differs from the examples. In that case, I would use a regular expression to get the nuber part from the beginning. If there is no number part or there is only number part, then let's just print it. 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))
5th Jan 2017, 12:26 PM
DFX
DFX - avatar
- 1
multiply it by calculator
5th Jan 2017, 11:01 AM
Adnan Ashraf
Adnan Ashraf - avatar