title: Remove characters from a string only when they occur in a certain order in python
body: <p>I am trying to clean up this string "cha?ra\ncter num?\nber". I want it to remove "?" and "\n" without removing "n" when it is alone. I tried the following, but it doesn't work. Any advice appreciated!</p>
  
  <pre><code>data_doc='cha?ra\ncter num?\nber'
  code={"?":"", "\n":""}
  table=str.maketrans(code.keys())
  data_doc.translate(table)
  </code></pre>