import res = "p2 k1"print( re.sub("([kp])([1-9])", lambda x: "0" * int(x.group(2)) if x.group(1) == 'p' else "1" * int(x.group(2)),s) )
Standard input is empty
00 1
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!