def make_converter(match, replacement):
d={match : replacement}
return d
def apply_converter(converter, string):
c1= "".join(str(x) for x in converter.keys())
c2= "".join(str(x) for x in converter.values())
print c1,c2
c3=string.find(c1)
if c3==-1:
return string
string=string.replace(c1,c2,1)
apply_converter(converter,string)
# For example,
c1 = make_converter('aa', 'a')
print apply_converter(c1, 'aaaa')
#>>> a
c = make_converter('aba', 'b')
print apply_converter(c, 'aaaaaabaaaaa')
#>>> ab
def make_converter(match, replacement): d={match : replacement} return d def apply_converter(converter, string): c1= .join(str(x) for
Share
You’re not returning the result of the recursion. Your function returns the input
stringif no match is found, otherwise it returns nothing at all!You want: