I need to replace some characters as follows: & ➔ \\&, # ➔ \\#, ...
&
\\&
#
\\#
I coded as follows, but I guess there
Maybe a simple loop for chars to replace:
a = '' to_replace = ['&', '#'] for char in to_replace: a = a.replace(char, "\\"+char) print(a) >>> \&\#