Python - removing some punctuation from text
<p>I want Python to remove only some punctuation from a string, let's say I want to remove all the punctuation except '@'</p>

<pre><code>import string
remove = dict.fromkeys(map(ord, '\n ' + string.punctuation))
sample = 'The quick brown fox, like, totally jumped, @man!'
sample.translate(remove)
</code></pre>

<p>Here the output is </p>

<pre><code>The quick brown fox like totally jumped man
</code></pre>

<p>But what I want is something like this </p>

<pre><code>The quick brown fox like totally jumped @man
</code></pre>

<p>Is there a way to selectively remove punctuation from a text leaving out the punctuation that we want in the text intact?</p>

<p>Just remove the character you don't want to touch from the replacement string:</p>

<pre><code>import string
remove = dict.fromkeys(map(ord, '\n' + string.punctuation.replace('@','')))
sample = 'The quick brown fox, like, totally jumped, @man!'
sample.translate(remove)
</code></pre>

<p>Also note that I changed <code>'\n '</code> to <code>'\n'</code>, as the former will remove spaces from your string.</p>

<p>Result:</p>

<pre><code>The quick brown fox like totally jumped @man
</code></pre>

python