With Python2.6 or better, there’s no need to define your own function; the string format method can do all this for you:
In [18]: '{s:{c}^{n}}'.format(s="dog",n=5,c="x")
Out[18]: 'xdogx'
Using f-string: f'{"dog":x^5}'
With Python2.6 or better, there’s no need to define your own function; the string format method can do all this for you:
In [18]: '{s:{c}^{n}}'.format(s="dog",n=5,c="x")
Out[18]: 'xdogx'
Using f-string: f'{"dog":x^5}'