I need to replace some characters as follows: & ➔ \\&, # ➔ \\#, ...
&
\\&
#
\\#
I coded as follows, but I guess there
Here is a python3 method using str.translate and str.maketrans:
s = "abc&def#ghi" print(s.translate(str.maketrans({'&': '\&', '#': '\#'})))
The printed string is abc\&def\#ghi.
abc\&def\#ghi